Back to "default transform" after animation interrupts

I think the answer is simple but I don’t get it and don’t know how to search for it.

I have two animations (spawnmainAnim). They are animated separately and should build on one another. This means “mainAnim” does not contain the keyframes of “spawn”.
The default transform of the GameObject is the last frame of the “spawn” animation.

Now let’s say:

  • the “spawn” animation does scale the object from 0.01 to 1 on z (And only contains scale keyframes)
  • the “mainAnim” animation moves the
    object from 0 to 1 on x (And only contains position keyframes)
  • Without animations, the model is scaled to 1.

If I interrupt the animation (by say deactivating the GameObject). Then the default state is the last animated frame. In this case, the scale is 0.5 now. This also means if I reactivate the GameObject the spawn animation starts as it should (scales from 0 to 1) but if the “mainAnim” starts the scales goes back to 0.5 because this is the “default transform” now.

gif of the problem

I hope you understand my problem.
How can I prevent this to happen and tell the animation no matter what the default transform is scale = 1?

Thank you

Create an ideal animation and do not deactivate the object with SetActiv(false).
Create a method e.g “Despawning” on the target you want to SetActiv(false). In this method jump quickly to the idle animation before you deactivate the object. You can also try this with the OnDisable event.

I used a coroutine for this to be sure.

    yield return new WaitUntil(() => sceneAnimator.GetCurrentAnimatorStateInfo(0).IsName("idle"));

Also if you are creating animations (in e.g Maya, Blender, etc.) make sure to set a “default” keyframe at the beginning and end of your animation clip for all values you are editing.