- Home /
Runtime instantiated prefab doesn't animate
I'm trying to make my character instantiate it's model in runtime (because I have different skins for it). What I have now is all the code, colliders and animator in a parent gameobject and I'm trying to instantiate the model related to the chosen skin in runtime.
For some reason the model doesn't animate when I do that.
If I put the same model prefab inside the character and instantiate it as one it works without any problem.
The visual prefab does not have any components on it.
As shown in the image, "Character_WithDefaultSkinModel" works perfectly, but when Instantiating Character_empty and then instantiating "Character_DefaultSkinModel" and setting it's parent to the Chracter_empty, the model doesn't animate.
EDIT:
I just realised that acessing the Animator and enabling then disabling the "Apply Root Motion" checkbox the character starts animating again.
It's like the component needs a reset, does anyone have an idea why? and how to force it properly
Answer by CaioRosisca · Mar 14, 2017 at 06:30 PM
I just solved it, all I needed to do was to call Animator.Rebind();
Great man... This is awesome work like a charm. Thanks a lot...
Hey CiaoRosisca,
i'm not sure if you are still active, but I wanted to ask you where did you put the "Animator.Rebind()" exactly? You have your script for the animation in you parent object, right?
Currently i'm at the problem that I can instantiate a Prefab as a child, but (while the already instatiated object works perfectly finde) the new instantiated is not using the animations (the movement script including the animation scripts are all in the Parent).
Thank you so much! I was having this exact problem. I was spawning in an object using instantiate and then immediately triggering the animator to play, but it wasn't working until I added rebind! YAY.
Answer by hexagonius · Mar 14, 2017 at 06:12 PM
might not be that easy, but you definitely missed a step:
https://docs.unity3d.com/ScriptReference/Animator-avatar.html
Answer by lgarczyn · Mar 14, 2017 at 06:12 PM
You might just be calling Instantiate() on a gameobject in your scene rather than on a prefab (gameobject in your asset folder).
Your answer
Follow this Question
Related Questions
Attaching a child object to a parent object that animates it in runtime 0 Answers
Animator not animating a runtime instantiated child 0 Answers
Prefab animation only plays on first instance 1 Answer
Animation questions (newbie) 1 Answer
Setting animator parameter on a single instance of a prefab sets the parameter for all instances 3 Answers