You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've seen this come up every now and then as a question in the Discord, so it's probably worth documenting in the cheatbook.
The following is a solution I've posted to discord:
// We'll use a bevy::time::Timer to wait X time.// Prefer a bevy Timer over a generic Timer for more accurate readings#[derive(Resource)]structMyStateTimer(Timer);// When we enter a specific state, start the timer.fnstart_timer(timer:ResMut<MyStateTimer>){
timer.0 = Timer::new(YOUR_DURATION_HERE,TimerMode::Once);}// We initialize the app with a non-running timer
app.add_resource(MyStateTimer(Timer::new(Duration::from_secs(0),TimerMode::Once)));// Don't forget to register the timer starting system for when the state is entered.
app.add_systems(OnEnter(MyState), start_timer);// Now here's where we do our delayed logicfnmy_system(timer:ResMut<MyStateTimer>,/* ... */){// We only run logic if the timer has completed, and only when it has *just* completedif(timer.just_finished()){// run your logic here}}// Don't forget to register it!
app.add_systems(my_system.run_if(in_state(MyState)));
The text was updated successfully, but these errors were encountered:
I've seen this come up every now and then as a question in the Discord, so it's probably worth documenting in the cheatbook.
The following is a solution I've posted to discord:
The text was updated successfully, but these errors were encountered: