6 releases

0.14.2 Sep 6, 2024
0.14.1 Aug 2, 2024
0.14.0 Jul 4, 2024
0.14.0-rc.4 Jun 27, 2024

#365 in Algorithms

Download history 577/week @ 2024-06-08 942/week @ 2024-06-15 664/week @ 2024-06-22 3262/week @ 2024-06-29 6620/week @ 2024-07-06 5903/week @ 2024-07-13 7394/week @ 2024-07-20 6902/week @ 2024-07-27 6461/week @ 2024-08-03 7596/week @ 2024-08-10 6446/week @ 2024-08-17 6576/week @ 2024-08-24 6745/week @ 2024-08-31 7737/week @ 2024-09-07 7400/week @ 2024-09-14 7228/week @ 2024-09-21

30,128 downloads per month
Used in 117 crates (12 directly)

MIT/Apache

3MB
50K 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–9MB
~148K SLoC