Bones work when manually adding object to scene, but not when instantiated in code; why?

So I have a simply mesh that is basically a cylinder, which has a spine of bones that each control a single edge ring in the mesh (a circle of vertices).

When I drag this object into the scene manually, I am able to play with the bones without any problem; the mesh moves as expected. However, once I instantiate it in code, only the first bone in the armature works; the others do absolutely nothing. If I change the root bone in the SkinnedMeshRenderer to one of the children, THEN that bone works, but none of the others.

The perplexing thing is that this did work without a problem before a code refactor, and now it no longer does. I have reduced my refactor down to simply instantiating the object to see if there is something I am doing afterwards that is breaking this, but it is STILL broken. In fact, when I manually drag my object in while the game is running; bones are broken there too. they only seem to work in edit mode.

Is my project corrupted? Anybody else have this problem? Any idea what I can do to fix this? I am using 2017.1.0p4

How does the hierarchy of your object look like? The “root bone” is only relevant for things like root motion. The actual link between the skinned mesh renderer and the individual bones is made by the [bones array of the skinned mesh renderer][1]. This array is not shown in the inspector. When you import a model that has a skinned mesh renderer, Unity assigns the bone gameobjects it creates automatically to that array.

When you instantiate such an object all object references to sub objects will be preserved during the instantiate. So as long as all bone objects are somehow a child of the model you instantiate everything should work just fine.

Also make sure you don’t mark the object as “static” in the inspector. Is there any script attached to the object you drag into the scene?

It’s difficult to help you with your problem since we can’t see your object and setup.

As it turns out, I did not realize that if you pause the game in play mode, bones will not work correctly. If I refrained from pausing the game and then just moved the bones in the inspector, it turns out I could. I am not sure why pausing the game prevent bones from moving, but this tripped me up, because I was certain a different bug I was having was caused by this.

After being able to move the bones, I verified it was not the cause of the issue. Anyways, as far as this question is concerned, the TL;DR:

You cannot move bones in play mode with the game paused. They will not work correctly.