- Home /
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 (spawn -> mainAnim). 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.
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
Answer by gwuwer-mms · Aug 14, 2020 at 08:45 AM
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.
sceneAnimator.Play("idle"); yield return new WaitUntil(() => sceneAnimator.GetCurrentAnimatorStateInfo(0).IsName("idle")); gameObject.SetActive(false);
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.
Your answer
Follow this Question
Related Questions
Not all animations are replaced when using an Animator Override Controller 0 Answers
Multiple Chracter(from same prefab) with same Animator does not work 0 Answers
Animation Control 0 Answers
How to add a curve to a .anim ? 0 Answers
How do I animate a character in unity with a humanoid skeleton? 0 Answers