Despite this being a simple problem, its going to be a large post.
I’m using a very basic animation to create a transition between rounds for my 2D mobile game.
Goal:
-
Once a round ends, play a short animation which then leads to the next round.
-
The ChangeRound animation is about 1 second long. It enables the UI image at the beginning, and disables it at the end of the animation.
-
It also has an AnimationEvent called OnChangeRound() that tells the game to start the next round.
Problem:
-
Animation is playing, but the enable/disable gameobject property is not triggering.
-
Additionally, the event is also not triggering.
-
During gameplay, I am unable to manually toggle the gameobject’s active state on/off. It is not being controlled by a script, and the animation is not playing at the time.
What I’ve done for debugging:
-
Made sure I wasn’t on the animation tab’s preview so it wouldn’t lock it
-
The AnimationEvent plays when I push the event keyframe farther from the end. When its about 1-5 frames near the end it never works, but if its at least 15+ frames from the end the event plays
-
Animator Window shows that the animation is definitely playing, and the previous point also lets me know for sure that the animation is playing.
-
Debug statements that prove all the correct functions are firing
-
Removed any layers from the Animator to ensure its always playing the correct animation
Script:
1. public void ChangeRound()
2. {
3. Debug.Log("Starting change round");
4. ClearLog();
5. _animator.Play("ChangeRound");
6. }
7. public void OnChangeRound()
8. {
9. Debug.Log("Changed Round");
10. GameManager.instance.StartGame();
11. }
Animator:
-
Sits in an Idle state by default, doesn’t do anything
-
I use animator.Play() instead of trigger/bool transitions since there are no other animations ever playing
Heirarchy:
-
The HUDScripter contains the script and Animator component
-
I’m just trying to enable/disable the Erasers gameobject. Currently its a UI image w/ a white square for testing purposes
Animation:
-
Simple animation clip. Works fine when previewing it
-
Enables the gameobject at the beginning, then disables it at the end.
-
Will play the OnChangeRound() event at the animation event
Website wouldn’t allow me to upload 3rd picture
I am completely baffled that this is not working. I’ve made plenty of basic animations before and this seems like such a straightforward function that completely refuses to work. I imagine I’m missing something very simple but I’ve spent hours on this with no solution. Any help would be appreciated