#does States really require Hash and Copy traits in 0.10?

13 messages · Page 1 of 1 (latest)

nocturne vapor
#

While trying to port my game from 0.9 to 0.10, I getting this error:

I'm getting this error
error[E0277]: the trait bound `states::GameStates: Hash` is not satisfied
  --> crates/game/src/states/mod.rs:18:10
   |
18 | pub enum GameStates{
   |          ^^^^^^^^^^ the trait `Hash` is not implemented for `states::GameStates`
   |
note: required by a bound in `States`
  --> /home/set/.cargo/git/checkouts/bevy-f7ffde730c324c74/43ea6f2/crates/bevy_ecs/src/schedule/state.rs:40:68
   |
40 | ...ne + PartialEq + Eq + Hash + Debug + Default {
   |                          ^^^^ required by this bound in `States`
help: consider annotating `states::GameStates` with `#[derive(Hash)]`
   |
18 | #[derive(Hash)]
   |

error[E0277]: the trait bound `states::GameStates: Clone` is not satisfied
  --> crates/game/src/states/mod.rs:18:10
   |
18 | pub enum GameStates{
   |          ^^^^^^^^^^ the trait `Clone` is not implemented for `states::GameStates`
   |
note: required by a bound in `States`
  --> /home/set/.cargo/git/checkouts/bevy-f7ffde730c324c74/43ea6f2/crates/bevy_ecs/src/schedule/state.rs:40:43
   |
40 | pub trait States: 'static + Send + Sync + Clone + PartialEq + Eq + Hash + Debug + Defa...
   |                                           ^^^^^ required by this bound in `States`
help: consider annotating `states::GameStates` with `#[derive(Clone)]`
   |
18 | #[derive(Clone)]

but according to this example https://github.com/bevyengine/bevy-website/blob/cc3099aef6c30125d375ba363be4a3f5297cd880/content/news/2023-03-04-bevy-0.10/index.md#user-content-simpler-states there should not be hash and copy traits

my code is simple:

#[derive(States, PartialEq, Eq, Debug, Default)]
pub enum GameStates{
  #[default]
  Loader,
  Init,
  Menu,
  Game,
  Pause,
  Test,
  TestBullets,
  Empty,
  LavaBiome,
  DungeonBiome
}
GitHub

The source files for the official Bevy website. Contribute to bevyengine/bevy-website development by creating an account on GitHub.

#

does States really require Hash and Copy traits in 0.10?

#

also, if I do add hash an copy than I start getting another error in another place, where I'm trying to add system in this state

.add_system(bullet_init.in_set(OnEnter(GameStates::Init)));

it then complains about FreeSystemSet trait
```error[E0277]: the trait bound bevy::prelude::OnEnter<states::GameStates>: FreeSystemSet is not satisfied
--> crates/game/src/pawns/bullet/bullet.rs:58:38
|
58 | .add_system(bullet_init.in_set(OnEnter(GameStates::Init)));
| ------ ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait FreeSystemSet is not implemented for bevy::prelude::OnEnter<states::GameStates>
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait FreeSystemSet:
CameraUpdateSystem
InputManagerSystem
InputSystem
OnUpdate<S>
PrepareAssetSet
RenderFogSystems
RenderLightSystems
RenderSet
and 9 others
note: required by a bound in bevy::prelude::IntoSystemConfig::in_set
--> /home/set/.cargo/git/checkouts/bevy-f7ffde730c324c74/43ea6f2/crates/bevy_ecs/src/schedule/config.rs:233:31
|
233 | fn in_set(self, set: impl FreeSystemSet) -> Config {
| ^^^^^^^^^^^^^ required by this bound in IntoSystemConfig::in_set

warm mirage
#

OnEnter and OnExit are Schedules so you've got to use .in_schedule() instead

nocturne vapor
#

and for OnUpdate it would be in_set, right?

warm mirage
#

Yup

nocturne vapor
#

thus seems pretty unintuitive. What is the logic behind this?

manic ginkgo
#

OnUpdate is basically just "only run if we're in this state"

#

While the transitionary logic needs to be fully atomic

#

As a result, update logic just runs in the main schedule, while separate schedules are needed for the transition, which are run back-to-back in a dedicated exclusive system

nocturne vapor
#

@manic ginkgo thank you for the explanation. though, I need to meditate on this a bit, for full understanding )

manic ginkgo
#

Yeah ❤️ It's a bit unfortunate that the implementation details are leaky, I'd like to add sugar eventually