I am trying to wrap my head around the Unity animation system. I am not talking about Mecanim here, I am talking about the basic/generic property animation stuff. Basically I am trying to create the effect of an object shooting up in the air, flipping around and landing again (imagine flipping a pancake). The problem I am having is that the animation seems to be playing automatically a single time when the object is instantiated. These are the steps I am taking:
- Select the object I want to animate in the scene
- With the object selected click Add Curve in the Animation tab
- Add some keyframes to create the animation
- Finish creating the animation
- Play the scene
The object will loop according to the animation.
If I go to the animation in the Assets and uncheck “Loop Time” the object will still play the animation but it will do it just once
How can I prevent this behaviour? I want to set up an animation so I can call it from code. Also, ideally I want the keyframes to be additive so this animation will always be relative to the object’s previous position (is this possible?)
Thanks!
Using animation can solve the problem, but you can also do this using Animator Just right-click your default animation state in Mecanim editor and choose: Set as default
Just make sure the “Play Automatically” flag is unchecked on the Animation component inside the Inspector.
When you are creating animations on position, make sure that the object you are animating is a child of another object. Otherwise, you will find that your object locks in place, as the animator component will override the rigidbody component.
Also, to answer your animation blending question, add a layer in your Animation. That will blend the higher layer animation with whatever lower level of animation is currently happening.
You have to use an “Animation” component, not an “Animator” one. (You can assign this by clicking on “Add Component”, “Miscellaneous” and “Animation.” This will contain the “Play Automatically” button you were looking for.
The best way I’ve found to solve this is to add an “idle” animation that does nothing and make it the default, then use Animation Parameters to trigger the pancake flip animation.