Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Call event on start transition

Discussion in 'Animation' started by Mathy, Mar 19, 2021.

  1. Mathy

    Mathy

    Joined:
    Jan 19, 2013
    Posts:
    2
    OnStateEnter is called right when you enter a state, but OnStateExit isn't called until you are completely out of the previous state. I would like to trigger something with the same timing as OnStateEnter, but either (A) on the state I'm exiting or (B) I want to know from where I'm transitioning on StateEnter. Or in other words, how can I implement a sort of OnStateExitBegin?
     
  2. Lekret

    Lekret

    Joined:
    Sep 10, 2020
    Posts:
    342
    OnStateExit is already fired in the same frame with OnStateEnter, afaik entering the state is the exact thing which forces previous state to exit. So you can probably put your code to OnStateExit and see all information about what state you are exiting.
    You can also try and make StateMachineBehaviour for whole layer or an MonoBehaviour with reference to an animator which will check state everyframe, so in OnStateEnter you just check information about last frame state or something like that.