-
-
Couldn't load subscription status.
- Fork 4.2k
Description
Commands in general shouldn't even have errors, and all our built-in commands should be infallible.
The panic that happens when an
insertorremovecomes after adespawnis something we just arbitrarily do. They should just be ignored (with adebug!warning). It isn't a bug if two different systems from two different plugins want to despawn an entity at the same time for different reasons, or if a plugin system wants to despawn an entity at the same time user code wants to give it a component, assuming it'll still exist. Batching does not add anything new to this equation.All we need to do is make a PR that (1) changes the panic to a
debug!warning and (2) privates all fields of [Insert][1], [Remove][2], and [Despawn][3] so that users can only make these commands throughEntityCommands. You can't get anEntityCommandsfor an entity [unless that entity is alive][4] (or will be), so all commands created throughEntityCommandsmust be considered valid.Since commands modify the shared state of the world, I don't think they could be reordered safely, unless we know ahead of time the set of all commands and all of their interactions, which is impossible with custom commands and will make adding new commands very difficult and fragile.
The reality is that custom commands should never make implicit assumptions about which entities exist and what components they may or may not have. i.e. If you pushed
<custom command 1>assuming thatMasswon't have been added toe2yet, that isn't safe to assume. I don't think we explicitly encouraged assuming things before, but it'd be actively discouraged after this.
Originally posted by @maniwani in #10154 (comment).
Having seen the problems that can arise, I think I generally agree. It's very hard to get a usable error handling solution (#2004, #2241) without severely compromising performance. And in any case, panicking is a very bad default, both for beginners (frustration), prototyping (wasted time) and production games (crashes are very bad).
Steps to fix
- remove
try_insertmethod - swap all panics to a
debugwarning in commands - make fields private
- get SME-ECS to agree that we should do this