Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with using StateMachine as Bevy Component #17

Closed
DylanRJohnston opened this issue Dec 21, 2023 · 2 comments
Closed

Problem with using StateMachine as Bevy Component #17

DylanRJohnston opened this issue Dec 21, 2023 · 2 comments

Comments

@DylanRJohnston
Copy link
Contributor

DylanRJohnston commented Dec 21, 2023

Hey all, I noticed the Bevy feature flag when installing statig which allows StateMachine to implement Component however I can't seem to get this to work correctly. I get the error

the trait bound `statig::prelude::StateMachine<monster::Behaviour>: bevy::prelude::Component` is not satisfied
the following other types implement trait `bevy::prelude::Component`:
  animation_link::AnimationLink
...

Code snippets

#[derive(Bundle)]
pub struct MonsterBundle {
    pub scene: SceneBundle,
    pub speed: Speed,
    pub stats: Stats,
    pub animations: NamedAnimations,
    pub behaviour: StateMachine<Behaviour>,
}

#[derive(Default)]
pub struct Behaviour;

pub enum Event {
    TimerElapsed,
    Start,
    Stop,
    Dance,
}

#[state_machine(initial = "State::idle()")]
impl Behaviour {
    #[state(entry_action = "enter_idle")]
    fn idle(event: &Event) -> Response<State> {
...

Wrapping it in a newtype seems to work correctly

#[derive(Component)]
pub struct BehaviourState(pub StateMachine<Behaviour>);
@DylanRJohnston
Copy link
Contributor Author

It seems this is just a problem with a mismatch in the bevy_ecs version.

@mdeloof
Copy link
Owner

mdeloof commented Dec 22, 2023

Solved with #18

@mdeloof mdeloof closed this as completed Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants