pub trait States: 'static + Send + Sync + Clone + PartialEq + Eq + Hash + Debug { }
Expand description

Types that can define world-wide states in a finite-state machine.

The Default trait defines the starting state. Multiple states can be defined for the same world, allowing you to classify the state of the world across orthogonal dimensions. You can access the current state of type T with the State<T> resource, and the queued state with the NextState<T> resource.

State transitions typically occur in the OnEnter<T::Variant> and OnExit<T::Variant> schedules, which can be run via the apply_state_transition::<T> system.

Example

use bevy_ecs::prelude::States;

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States)]
enum GameState {
 #[default]
  MainMenu,
  SettingsMenu,
  InGame,
}

Object Safety§

This trait is not object safe.

Implementors§