1
\$\begingroup\$

I'm using a very basic animation to create a transition, which involves deactivating a gameobject on the last keyframe.

Goal:

  • 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.

Problem:

  • Animation is playing, but the gameobject is not disabled in the last keyframe. Note that all my states have "Write Defaults" set to false.

What I've done to fix it:

  • If I move the keyframe which disables the gameobject one frame before, then the object gets disabled correctly. Note that in the Animation clip picture below, I also animate other properties, so moving the disable-keyframe 1 frame before doesn't shorten the animation (i.e. the picture below is a semplification).

Hierarchy:

  • The HUDScripter contains the Animator component.
  • I'm just trying to enable/disable the Erasers gameobject.

Animation:

  • Simple animation clip. Works fine when previewing it
  • Enables the gameobject at the beginning, then disables it at the end (again, actually there are other properties being animated, not just the disabling of the gameobject, so moving the disable keyframe one frame before doesn't shorten the animation by 1 frame).

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.

Actually, I'd like to know if there's something different from moving the disable keyframe 1 frame before and also if this is a reliable workaround. I'm thinking to use the StateMachineBehaviour to detect if we are leaving a state of the animator finite state machine, but using the animation clip to enable / disable gameobjects was so comfortable... What about putting an animation event on the last keyframe? But most of all I'm interested in why the first approach doesn't work.

Note: this question was adapted from here

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Final frame sampling in Unity is not guaranteed and this has been an issue for a very long time, move your de-activation earlier or don't use it in the animation editor at all. This is due to the timing of sampling and frame rendering/processing. Use a script to detect the end of the animation or move it earlier in the animation state. There are MANY cases of final frame issues in the unity forums.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.