-
-
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
Add OnTransition schedule that is ran between OnExit and OnEnter #7936
Add OnTransition schedule that is ran between OnExit and OnEnter #7936
Conversation
Example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The schedule needs to be initialized via App::add_state
.
Cool idea though, I like it!
Strong preference for named fields (from
and to
perhaps?) for the OnTransition
type though.
Done 👍 Although since there isn't a way to lazily initialize a Schedule (AFAIK), this might incur a good amount of overhead for States that have a lot of variants. Might be worth a benchmark. |
crates/bevy_app/src/app.rs
Outdated
to: second, | ||
}, | ||
Schedule::new(), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This eagerly registers schedules that scales quadratically with the number of variants in a state set. Not all of them may be necessary, and will still use memory. Is there a way to do this lazily?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we merge #7911 first we can actually remove all of the schedule registration logic from this method. Which I think I prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer this as well. We wait for #7911 then.
#7911 has been merged. |
ab109d1
to
ae7383e
Compare
Updated. Since schedules can be lazily initialized now, there shouldn't be a need to register OnTransition now right? |
Example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rerun cargo fmt --all
to fix CI
from: exited, | ||
to: entered.clone(), | ||
}; | ||
if world.resource::<Schedules>().contains(&transition_schedule) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a try_run_schedule
. But that can be handled in a different PR.
Objective
Fix #7647
Solution
Implements the solution described by @LiamGallagher737 in #7647.
Changelog
Added
OnTransition
: Alternative to OnEnter and OnExit to enable more specific state transition logic.