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

How to correctly use Update and FixedUpdate? #39

Open
omid3098 opened this issue Aug 21, 2021 · 3 comments
Open

How to correctly use Update and FixedUpdate? #39

omid3098 opened this issue Aug 21, 2021 · 3 comments

Comments

@omid3098
Copy link

Hi,
I'm using this simple example like you described in Readme:

using MonsterLove.StateMachine;
using UnityEngine;
public class FSMTest : MonoBehaviour
{
    public enum States { Init }
    StateMachine<States> fsm;
    void Awake()
    {
        fsm = new StateMachine<States>(this);
        fsm.ChangeState(States.Init);
    }
    void Init_Enter() { Debug.Log("Init_Enter"); }
    void Init_FixedUpdate() { Debug.Log("Init_FixedUpdate"); }
    void Init_Update() { Debug.Log("Init_Update"); }
}

But the Update and FixedUpdate wont execcute.
What am I missing?

@LeeHyeonJae97
Copy link

Hi, I was struggling with that too. Look into the script 'StateMachineRunner.cs'. You will need this component to call the Update, FixedUpdate, LateUpdate methods.

@Barbelot
Copy link

Barbelot commented Mar 28, 2022

I had the same issue which I solved by replacing

fsm = new StateMachine<States>(this);
fsm.ChangeState(States.Init);

by

fsm = StateMachine<States>.Initialize(this, States.Init);

This was the initialization step shown in an older version of the README.
Not sure if this is the correct way to initialize now but it seems to work.

@wes-kay
Copy link

wes-kay commented Dec 2, 2022

For everyone else who doesn't want to wade through code, the samples tell you how:

private void Update()
{
    fsm.Driver.Update.Invoke(); //Tap the state machine into Unity's update loop. We could choose to call this from anywhere though!
}

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

4 participants