Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Guavaman

Pages: [1]
This doesn't seem to make much sense to me. An Action's OnEnter gets fired every time an Fsm.Event is called causing infinite loops if you ever fire an event from within OnEnter.

Take this example:

Code: [Select]
public class TestAction : FsmStateAction {

        public bool everyFrame = true;
        public FsmEvent onTrueEvent;

        public override void Reset() {

        public override void OnEnter() {
            DoUpdate(); // this will cause an infinite loop because onTrueEvent will be fired from within OnEnter, then OnEnter will run again, over and over...
            if(!everyFrame) Finish();

        public override void OnUpdate() {

        public void DoUpdate() {

            // Just fire when X is pressed for testing
            if(Input.GetKeyDown(KeyCode.X)) {
                // Fire event
                if(onTrueEvent != null) Fsm.Event(onTrueEvent);

  • Add the TestAction to the default FSM state.
  • Add a Finished event and a new state.
  • Connect the Finished event to the new state.
  • Set the onTrueEvent to Finished in the inspector.
  • Press Play.
  • Hit X to fire the event.

GameObject : FSM : Loop count exceeded maximum: 1000 Default is 1000. Override in Fsm Inspector.

Adding some debug logging reveals that for every time the onTrueEvent is fired, OnEnter is run again, causing onTrueEvent to be fired again, then OnEnter to run again, etc.

Is this behavior intentional? It doesn't make sense to me that firing an event that should initiate the transition to the next state should then cause the same calling FSM state to be entered again and OnEnter to be called on the Actions.

Pages: [1]