Confusion about State
& NextState
when adding a State resource in a system
#17638
Unanswered
danielmckinnonanderson
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I'm confused about the usage of State / NextState and how they fit into the timings of the app when the state is initialized manually rather than while building the app.
I have declared some state to use in my game that should only exist during specific timings of my app. This state should only exist in the world when we're in turn-based combat:
Since the game starts at a menu, and only proceeds to this turn based combat vertical slice after selecting that option from the menu, it makes sense that I would not call
app.init_state
in my plugin for this capability.Instead, the state is initialized at the top of the system which fires on this triggering event like so:
So far so good. My understanding of the way this works in Bevy is that at the end of the frame, these commands are executed and my State will be added. I would expect that at that same point is when the
NextState
resource is added, in sync with this declared state if no otherState
of this type existed before.Where I'm getting confused then, is why a system I intend to run after this to change the variant of the state from
Setup
toFighting
never triggers, becausemove_to_fighting_state_sys did not run because it requested inaccessible system parameter ResMut<NextState<TurnBasedCombatState>>
.I have tried a few orderings of these systems to try and fulfill the condition where the
NextState
is setup, including running this system before thesetup_new_combat_sys
so that it would be run first after the updates on this frame complete, which is when I assumed that theNextState
would be ready. Currently I have the scheduling as this, in my plugin:Am I doing something wrong with the initialization of my state resource? Is there a different pattern I need to use to achieve this behavior?
Per this discussion, is the best choice for implementing what I'm describing to manually add both the
State
andNextState
to the world prior to either of the systems described here running? Is my mental model of these state transitions & resource initializations incorrect?Beta Was this translation helpful? Give feedback.
All reactions