#SystemSet `on_update` running before `on_enter` (or `on_enter` not running?)

2 messages · Page 1 of 1 (latest)

outer ridge
#

Hi- I've made a change to my app where instead of directly changing its main State<T>, I defer that to a system update_state() that runs in a specific stage (1), in an attempt to limit the random points where the app can change state.

Unfortunately, now there's (randomly, race condition; sometimes it works, sometimes not) several systems scheduled for on_update() running before the system scheduled for the on_enter() of the same State<T>, which causes obvious issues/crashes.

(1) It doesn't seem to matter when the update_state() system is scheduled; I've tried CoreStage::First, CoreStage::Update, and CoreStage::Last, and tried at_start(), at_end() and nothing (unspecified). In all cases I have random crashes.

a. I don't understand why this makes any difference with directly changing the State<T>?
b. I suspect that the on_enter() somehow "misses" the state change and gets skipped if the associated system doesn't run in the same stage as update_state().
c. All of that looks extremely brittle. Can we only change a State<T> in a single stage?

#

Also not that it seems the State<T> is updated in the system state_cleaner() labelled DriverLabel::of::<T>(), but both the system and the label are private so third party code cannot synchronize with the system. Yet the comments in code say it's important that this system runs first before all other state-dependent sets. But users can't possibly ensure that can they?