Assign animation at runtime error


I’m letting our designers create animations for camera movement within Unity, and saving out those animations locally. What i’d like to do is at runtime choose an animation and assign it to the animation component on the camera and play it.
However, each time i try this i get an error “Default clip could not be found in attached animations list”.

In the inspector i can actually see that the animation component is referencing the animation, but it just wont play. I’m doing something to this effect:

Camera.main.animation.clip = m_storedAnimation;


Would it just be easier if all the animations are added to the animations array on the component during edit mode? Will this take up too much memory? (one of the reasons why i wanted to achieve this at run time).


First you can add animation during edit time. I just sounds to me that you don’t need to add them at runtime. But if you really want you can do it:

Camera.main.animation.AddClip(m_storedAnimation); // I can't remmeber if there are extra arguments