Search Unity

Question Inner state OnStateExit is called after parent sub-state machine OnStateMachineExit was called

Discussion in 'Animation' started by ShinAli, Mar 24, 2023.

  1. ShinAli

    ShinAli

    Joined:
    Sep 24, 2011
    Posts:
    36
    Say I have State Machine A that contains State 1 and a State Machine B.

    When State 1 hits an exit node that eventually leads directly to State Machine A's exit node, OnStateMachineExit for State Machine A is called as well as OnStateMachineEnter for State Machine B; after which, State 1 OnStateExit is called last.

    Is this a bug? Is this intended design? Is this situation "undefined behaviour"? Why on earth would this be the expected order of execution?
     
  2. ShinAli

    ShinAli

    Joined:
    Sep 24, 2011
    Posts:
    36
    Answered my own question from the Update Loop post.

    OnStateMachineEnter/Exit functions are called before any State callbacks. Extremely unfortunate design decision that has me implementing hacky solutions.