-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
State-dependent system runs twice on wrong add_state
call order
#1672
Comments
Another sub-bug of #1120 :( |
This... works as expected. bevy/crates/bevy_app/src/app_builder.rs Lines 180 to 183 in 284889c
which must be added first, as stated by its doc: bevy/crates/bevy_ecs/src/schedule/state.rs Lines 189 to 192 in 284889c
|
And also seemingly unavoidable: #1424 (comment) |
But running the system twice is still not expected behavior regardless the docs. |
This is a product of SystemSet run criteria evaluation order. I think providing some configuration for SystemSet insertion position is probably a nice quick solution to this. All we really need is for the driver system set to be inserted at the front by default and normal sets to be inserted at the back by default. This is slightly complicated by the fact that index 0 is reserved for the "default" system set (which always exists). But we can make "front" insertion just happen at index 1 instead. We could even make this configuration private (for now) so users can't accidentally insert a SystemSet at the front with state run criteria. This would also buy us time to design the "final" system set order api. I'm making these changes now, but feel free to discuss alternatives / pick this apart. |
This isn't quite as simple as I made it out to be because of the way we convert SystemSets (the "configuration") to virtual_system_set, parallel_systems, and exclusive_system lists (the "runtime state"). Upon insertion we store an index in each system container to the virtual_system_set index. This creates a situation where re-ordering virtual_system_sets invalidates all stored indices (which could happen at any point during app building). We'll either need to "fix" these indices when re-ordering occurs (or at some point before startup), use non-index ids to correlate, or change the lifecycle to ensure that when we populate the system container lists, the virtual system set indices are already stable. @Ratysz would any of the above changes mess with your planned ecs work? Do you have an opinion here? |
#1675 (the aforementioned "planned ECS work") does some of these changes itself and will include a way to specify run criteria evaluation order, so it should resolve this issue. |
Bevy version
main
branch on commit 284889c.Operating system & version
MacOS Catalina 10.15.7 (19H2)
What you did
Consider following snippet:
What you expected to happen
System
running_input
is called once per frame.What actually happened
System
running_input
is called twice per frame:Additional information
The result depend of when
add_state
was called.After swapping
add_state
andadd_system_set
likeeverything works just fine:
The text was updated successfully, but these errors were encountered: