I’m working on a prototype fighting game. Fighting game animations need to be frame tight, and work in tandem with user inputs. I’ve decided against using the default animator multithreading by disabling the animator when a character is enabled and manually triggering Animator.Update() on every character Update() frame. (this was recommended in a different thread in the forums that I can no longer find).
I’ve also set all transitions to have length 0, in the hopes that each frame would either be one call to the current state’s OnStateUpdate(), or a transition call to the first state’s OnStateExit() (with a call to the next state’s OnStateEnter() on the next frame).
In order to account for any movement or physics that may occur during an animation state, I was using the OnStateMove() call to handle all physics of moving the character based on a combination of inputs being read and the current state.
I have run into 2 problems with this setup:
-
Let’s say I initiate a transition from state 1 to state 2. I’ve noticed that the OnStateMove() for state 2 appears to be getting called for one frame after its OnStateExit() has been called. In fact it is getting called in the same frame that state 1’s OnStateEnter() is being called. How can I prevent this? I want to make sure that the OnStateMove() for each state only gets called while that state is active.
-
I read inputs from the user before calling animator.Update(). For some reason, calling animator.Update() like this does not trigger a transition when using OnStateUpdate() to set animator parameters. It ends up looking like an input is read, the animator updates, the same input is read, animator updates again, input is read one more time, and finally the animator calls OnStateExit() to begin transition. How can I ensure that the frame an input is read that a transition begins?
If using the Mecanim animator state behaviors is not optimal for this setup, I can try to code my own implementation, but I was really hoping I could lean into Unity as much as possible