I’m attempting to move a bone via script, mapping it to a certain variable (positions I get via a face tracker; to get e.g. jaw bone to follow the position of jaw tip read from camera).
Vertices assigned to the bone move fine when I manually enter Transform values in inspector, but nothing I attempt via scripting affects them; the model remains static, and Transform values in inspector do not change.
The setup:
Empty game object containing head mesh + bones > head bone as root bone > other bones as its children.
public Transform[ ] Objects; //Objects[0] gameobject containing everything, head bone is Objects[1], jaw bone Objects[2]
Objects[0] moves fine via Objects[0].transform.position or Objects[0].transform.rotation.
For jaw bone, I’ve tried::
Objects[2].transform.SetParent(Objects[1].transform, false); // also tried not adding false here
Objects[2].transform.localPosition = pos; // tried various positions; they are printed correctly using print
Objects[2].transform.position = pos; // same
Nothing affects it. What am I misssing/misunderstanding?
Do you have a running animator on the same object?
The animator moves all bones to the position it believes they should be in after Update, so even if you’re not running any animation, the bone positions will still be reset.
If that’s the case, move your code to LateUpdate, which runs after the animator. That’s where things like IK and other animation-editing stuff are supposed to go.
I know this is rather old, but since there’s so little documentation available, I wanted to mention to be sure you’ve checked that you have an animation controller available for your particular model – especially if you’ve got a humanoid animation going on – because, without this, the bone positions refuse to update for humanoid animations due to the fact that they are no longer pointing at the transforms directly, but are pointing (instead) to the humanoid shortcuts that eventually point to the transforms on the model. These “shortcuts” are not able to be translated without the Animation Controller however.