- Home /
Simple animation on game object doesn't play via animation.Play
Hot to reproduce the problem:
create a cube or any other primitive (also an empty object works). Let's say we call it MyObject
open the animation window and create a new clip. Let's say we call it anim01
attach an Animation component to the object and make sure that the anim01 is selected and appears in the list.
create a C# script with the following start function
void Start () {
animation.Play(); }
This will give the following warning:
The AnimationClip 'anim01' used by the Animation component 'MyObject' must be marked as Legacy. UnityEngine.Animation:Play(String) MyScript:Start() (at Assets/Scripts/MyScript.cs:10)
..and the following error:
The animation state anim01could not be played because it couldn't be found! Please attach an animation clip with the name 'anim01' or call this function only for existing animations. UnityEngine.Animation:Play(String) MyScript:Start() (at Assets/Scripts/MyScript.cs:10)
I just need to make a simple cube move with an animation. This, if am not wrong, was the way to play an animation before Unity 4.3? Is something changed? Am I missing something? Please help.
Thank you. RS
Actually.. it seems that recreating the animation from the scratch solved this issue. For some reason it looks like some inner link was lost by Unity for something I did, but I'm not sure what action broke it. Is this a bug? Still curious to see if others had this issue. I'll leave the question.
Here is a related post:
http://answers.unity3d.com/questions/577801/animation-must-be-marked-as-legacy.html
Answer by Rs · Dec 17, 2014 at 10:17 AM
If you had this issue it's very likely that you created the clip in Unity with the wrong format.
Animations, better said clips in this case, made for the Animator component aren't compatible with the Animation component. If you drag and drop a .anim asset that was created in Unity for Animator into an Animation clip slot it will not give you any fatal error but it won't play when it's supposed to.
In order to create an animation for the Animation component on a game object,
Add an Animation component to your game object.
Open the Animation window (not Animator) making sure the target game object is selected.
Create and save a new Clip.
Doing so you created an animation in the legacy format, which is compatible with the Animation component.
For similar reasons when you import animated objects from FBX or other formats, if you want to use the Animation component, you need to set the animation import to Legacy.
Hope this helps.
RS
That's very useful information, I didn't know animations created for the animator weren't compatible with the animation component, 7 years later that's still relevant, thank you!