- Home /
Issue about transforming animation in animation event and then in update function continuously
Hi, all, I got issues about transforming animations, I may have fixed it, but I still have some questions about it. The detailed case is here:
For my monster character, if it doesn't find player within time limit, it will turn round. This will call animator to play "flip" animation(Using animator.Play(name) for my 2D game). And the status parameter will be set to "FLIP"
In the last animation frame of the "flip", animation event will set the monster status to "IDLE" and play "idle" animation.(And "flip" animation is NOT a loop animation)
And then in my logic, I make one mistake. In the update function in the next frame, (I should have known that the animator event and animator update happens after update function.) because the status has been set to "IDLE", the monster continues to check the player, and this time, it find the player.
So, as the monster has turned round, it needs to turn round again to face the player, it calls the animator to play "flip" and set status to "FLIP".
That cause the problem. Because the state of the animator is still "flip", it will not be updated after the update function of the next frame. So the final animator state is "idle", and it has no animator event to set the related info of the monster to "idle" status. So the monster stuck :P.
So if I need to fix it directly, I can just use the play(name, layer, time) function and set time to 0, and this works. And there are lots of ways to fix such issue. But I have three question about it:
I've read some information about the Execution Order of Event Functions(https://docs.unity3d.com/Manual/ExecutionOrder.html) and we can know that the animation internal update happens after the update function. So I want to confirm that, is it whenever I call the Play function of the animator, it will always update the state of the animation in the animation internal update happens after the update function in this frame or next frame ? And is it true that the animation event happens after the animation internal update has been done?
The final state of the animator is "idle", but not stuck in "flip". Obviously, I set animator to play "idle" first in animation event and then in the function update of the next frame I set animator to play "flip" and this may be invalid. So the animator only response the "valid" call or only response the first call or something else?
When I used the mono IDE to debug my code to reproduce this issue, after the break point in the animation event hit, I tried to debug it frame by frame, but the console displayed a warning about CallBack (I'm sorry that I'm not using my own PC and cannot get the detailed warning message now, I'll update it later) and this issue didn't reproduce, the monster turned round successfully. XD, I'm very confused.
Can you please help me to find the answers of these two questions? Thanks very much!