Help with Animations and Prefabs!


I'm having problems when I try to put an animation inside a prefab that was created in Unity. I have a game object with I added an Animation Component, but when I add it to a prefab... the animation is gone. It is hard for me to believe that this cannot be done!!!


Have you tried...

Drag a prefab into the Hierarchy, creating an instance.
Add the animation.
Drag the instance on top of the original prefab in the project view, replacing it.


That's one way to go about this, but not the only way. If you have an animation in your Project view, and add it to a prefab's animation component, it should not disappear, either. Perhaps some more details would help.

Hello Jessy,

Sorry it did not worked. This is a detail of what I am doing:

1) Create a cube.
2) Add an Animation Component
3) Set key frames for the cube. (which are stored in the animation component)
4) Drag to a prefab in the project.

Now... when I drag the prefab back to the hierarchy, the component is still there, but the animation is set to (none), so there is no animation at all.

Got it. Here's what to do next time:

Create an animation in the Project view.
Select that animation from the drop-down box in the Animation component of your prefab.
Animate the prefab.

I don't know if there's a way to assign a prefab's animation to the the "Default" animation that you created for the cube, originally. Perhaps somebody else has a non-scripting method for this?

...I just realized that you can choose "Default" from the animation component after you place the prefab into the Hierarchy.

1 Like

Excelent! Thank you Jessy! I haven't used that "Animation" asset until now. I get the idea now...

In the similar fashion I created a bar chart using prefabs and I am unable to add animation that is I am trying to create a dynamic bar chart like on click of play button the bar charts should Rise to the statistical values from base but I am unable to achieve that. How can I achieve that