Open Jaso333 opened 1 month ago
IMO having entities "scoped to a particular state" is more simple concept than despawn-on-entry/exit. If StateScoped
gets warning (or even instant despawn) against insertion during mismatched state, then these new components could be added to fill the gaps for advanced use.
Note that this also opens the door to expanding the type into an enum as such (from pyri_state
):
pub enum DespawnOnExit<S: State> {
Single,
#[default]
Recursive,
Descendants,
#[doc(hidden)]
_PhantomData(PhantomData<S>),
}
Also "despawn on enter", "hide on enter", "hide on exit", "disable on enter" (with entity disabling), etc. variants become very reasonable to add.
What problem does this solve or what need does it fill?
The current naming of the
StateScoped
component is slightly misleading: it could be interpreted as "this entity will not exist outside of this state". Whereas in fact it merely despawns on exit of the given state, it doesn't care if you spawn an entity outside of the given state:To me, this functionality is fine, I can't think of a situation where you would want to spawn something in a state it doesn't belong, only for it to be deleted instantly.
There is also no available inverse of this component: despawn an entity on entry to a state, which I recently found a need for, and have written a very similar mechanism to achieve the same thing.
What solution would you like?
StateScoped
toStateExitDespawn
, or maybe a cleaner looking name than that.StateEntryDespawn
, having it operate during state transition, beforeOnEnter
.Here's a snippet of what I produced for my own game:
What alternative(s) have you considered?
No real alternatives.
Additional context
State transitions are such a powerful and flexible way to orchestrate game entity lifecyles and the flow of the game itself, it would be nice to see more features in this area.