- Home /
How to create an Animator and Animation at runtime
As the question says I'm trying to create animations and animators at runtime during code execution. I've tried Animator anim=new Animator(); Animation animation = new Animation(); but checking the exposed variables via the editor I see that they are listed as null. trying to use them gives me a null reference exception.
so how would I make these components at runtime. Yes I do need an individual animator and animation per game object, and they must be procedurally generated due to how the game runs
Answer by tanoshimi · Apr 03, 2014 at 09:32 PM
gameObject.AddComponent<Animator>();
gameObject.AddComponent<Animation>();
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.AddComponent.html
Your answer
Follow this Question
Related Questions
Card Game Unique abilities run dynamically 2 Answers
Instantiate a prefab vs create one dynamically at runtime? 1 Answer
How to change animation clips of an animator state at runtime? Is there a way? 5 Answers
Statically write .enabled for use with Android 1 Answer
Which is better: script or animation (which needs to change with scripting)? 1 Answer