bevy/crates/bevy_ecs/src
Lee-Orr 63eb151619
Optional state (#11417)
# Objective

Adjust bevy internals to utilize `Option<Res<State<S>>>` instead of
`Res<State<S>>`, to allow for adding/removing states at runtime and
avoid unexpected panics.

As requested here:
https://github.com/bevyengine/bevy/pull/10088#issuecomment-1869185413

---

## Changelog

- Changed the use of `world.resource`/`world.resource_mut` to
`world.get_resource`/`world.get_resource_mut` in the
`run_enter_schedule` and `apply_state_transition` systems and handled
the `None` option.
- `in_state` now returns a ` FnMut(Option<Res<State<S>>>) -> bool +
Clone`, returning `false` if the resource doesn't exist.
- `state_exists_and_equals` was marked as deprecated, and now just runs
and returns `in_state`, since their bevhaviour is now identical
- `state_changed` now takes an `Option<Res<State<S>>>` and returns
`false` if it does not exist.

I would like to remove `state_exists_and_equals` fully, but wanted to
ensure that is acceptable before doing so.

---------

Co-authored-by: Mike <mike.hsu@gmail.com>
2024-01-19 21:38:04 +00:00
..
entity Unified identifer for entities & relations (#9797) 2024-01-13 01:09:32 +00:00
identifier Unified identifer for entities & relations (#9797) 2024-01-13 01:09:32 +00:00
query Dynamic queries and builder API (#9774) 2024-01-16 19:16:49 +00:00
reflect Add ReflectFromWorld and replace the FromWorld requirement on ReflectComponent and ReflectBundle with FromReflect (#9623) 2024-01-19 16:08:57 +00:00
schedule Optional state (#11417) 2024-01-19 21:38:04 +00:00
storage Minimize small allocations by dropping the tick Vecs from Resources (#11226) 2024-01-08 22:39:47 +00:00
system Dynamic queries and builder API (#9774) 2024-01-16 19:16:49 +00:00
world Get Change Tick methods for Resources (#11404) 2024-01-18 15:58:13 +00:00
archetype.rs Rename ArchetypeEntity::entity into ArchetypeEntity::id (#11118) 2024-01-01 16:12:24 +00:00
bundle.rs Allow #[derive(Bundle)] on tuple structs (take 3) (#10561) 2023-11-21 01:09:16 +00:00
change_detection.rs Simplify conditions (#11316) 2024-01-13 13:22:17 +00:00
component.rs Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
event.rs Explain EventWriter limits concurrency (#11063) 2023-12-24 17:45:21 +00:00
lib.rs Add ReflectFromWorld and replace the FromWorld requirement on ReflectComponent and ReflectBundle with FromReflect (#9623) 2024-01-19 16:08:57 +00:00
removal_detection.rs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00