9 releases

0.15.0-rc.3 Nov 5, 2024
0.15.0-rc.2 Oct 27, 2024
0.14.2 Sep 6, 2024
0.14.1 Aug 2, 2024
0.14.0-rc.4 Jun 27, 2024

#318 in Game dev

Download history 6844/week @ 2024-07-29 6384/week @ 2024-08-05 7742/week @ 2024-08-12 5949/week @ 2024-08-19 6878/week @ 2024-08-26 7207/week @ 2024-09-02 6981/week @ 2024-09-09 8016/week @ 2024-09-16 8497/week @ 2024-09-23 8275/week @ 2024-09-30 7859/week @ 2024-10-07 7495/week @ 2024-10-14 7086/week @ 2024-10-21 7980/week @ 2024-10-28 7801/week @ 2024-11-04 6154/week @ 2024-11-11

29,903 downloads per month
Used in 130 crates (12 directly)

MIT/Apache

4MB
65K SLoC

In Bevy, states are app-wide interdependent, finite state machines that are generally used to model the large scale structure of your program: whether a game is paused, if the player is in combat, if assets are loaded and so on.

This module provides 3 distinct types of state, all of which implement the States trait:

  • Standard States can only be changed by manually setting the NextState<S> resource. These states are the baseline on which the other state types are built, and can be used on their own for many simple patterns. See the state example for a simple use case.
  • SubStates are children of other states - they can be changed manually using NextState<S>, but are removed from the World if the source states aren't in the right state. See the sub_states example for a simple use case based on the derive macro, or read the trait docs for more complex scenarios.
  • ComputedStates are fully derived from other states - they provide a compute method that takes in the source states and returns their derived value. They are particularly useful for situations where a simplified view of the source states is necessary - such as having an InAMenu computed state, derived from a source state that defines multiple distinct menus. See the computed state example to see usage samples for these states.

Most of the utilities around state involve running systems during transitions between states, or determining whether to run certain systems, though they can be used more directly as well. This makes it easier to transition between menus, add loading screens, pause games, and the more.

Specifically, Bevy provides the following utilities:

Dependencies

~6–16MB
~189K SLoC