- Home /
How to play character animation after bone deparent?
For a certain reason, I want to take apart a character's bones separately(a bone will have no parent and no child).
However, before an animation is advanced, bone structure is needed to be restored.
So referred to Unity execution order (http://unity3d.com/support/documentation/Manual/Execution%20Order.html ), my code is like this.
void Update()
{
ParentAllBones();
}
//animations are advanced...
void LateUpdate()
{
DeparentAllBones();
//execute some process
}
//rendering
/*
void ParentBone()
{
child.parent = parent;
}
void DeparentBone()
{
child.parent = null;
}
*/
But the animation isn't played. Where do I make mistakes? How can I separate bones and play character's animation?
I think you should explain why you think you need to bust up the hierarchy, because not doing that may be the simplest answer to your question. I certainly wouldn't be surprised if animations never worked again if you broke up the hierarchy!
$$anonymous$$y purpose is scaling character's bone, the same as this question (http://answers.unity3d.com/questions/137667/scaling-widthheight-of-a-characters-headbody.html ). And thanks to your former answer I nearly achieved my end. But I think that "Is the hierarchy the root of all evil?", so for an experiment I broke up the hierarchy.
I think I see what you're trying to do. Why don't you just reparent them immediately after doing "some process"? What are you hoping will happen in between the LateUpdate and next Update that you think leaving them deparented will help? Certainly rendering isn't going to be different because of the deparenting. The animation will fail if the hierarchy is not there when it is sampled, since it is defined using transform paths that correspond to the hierarchy.
Experimenting is good of course, but this seems to be getting far more expensive than just adding more bones. Why do you have a strict bone limit? No way will an extra tummy bone or such be anywhere near as expensive as any deparenting and reparenting process.
Answer by sneftel · Jul 11, 2011 at 01:43 PM
The constant parenting and deparenting may end up being a huge hit to performance -- not necessarily, but I'd stress test that early on, just to be careful. The basic issue with animations not playing is likely due to the base Animation component's references being invalidated. It's sort of a fragile component with respect to hierarchy changes.
In any case, flattening the hierarchy is NOT going to help you with your scale->skew issues, so don't waste your time on it. I'll explain in more detail on that question.
Answer by Paulius-Liekis · Jul 11, 2011 at 12:55 PM
I can't really remember if this should work (it depends on when animation tracks are rebound to transforms).
You could do this by having secondary skeleton (which is deparented) and then you would copy desired world-pose transforms from parented (invisible, but animated) skeleton.
Your answer
Follow this Question
Related Questions
animation.Play not affect specific bone 1 Answer
Is there a limit to the number of bones in a model 2 Answers
AnimationState.AddMixingTransform 1 Answer
Character assets bundles problems on skinned mesh 1 Answer
First Person Legs. 3 Answers