Trait bevy::ecs::prelude::States

pub trait States: 'static + Send + Sync + Clone + PartialEq + Eq + Hash + Debug {
    const DEPENDENCY_DEPTH: usize = 1usize;
}
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 by triggering the StateTransition schedule.

Types used as ComputedStates do not need to and should not derive States. ComputedStates should not be manually mutated: functionality provided by the States derive and the associated FreelyMutableState trait.

§Example

use bevy_ecs::prelude::States;

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

Provided Associated Constants§

const DEPENDENCY_DEPTH: usize = 1usize

How many other states this state depends on. Used to help order transitions and de-duplicate ComputedStates, as well as prevent cyclical ComputedState dependencies.

Object Safety§

This trait is not object safe.

Implementors§

§

impl<S> States for S
where S: ComputedStates,