Parenting an Object to a bone WITHOUT animation

Hi,

There have been many questions about parenting an Object to a bone, however all of them have an issue:

The Object only moves with the bone when the bone is updated as part of an animation, when the Character moves, the Object stays behind.

Furthermore, if the animation does not move the bone on every frame, the attached mesh lags behind.

Take a look here:
https://playground.babylonjs.com/#N4T4AJ#4 (Change line 60 to try workarounds below)

I found a few workarounds but they don’t seem to be optimal:
a) Mark bone as dirty on every step of the character
b) Move character with skeleton

My questions:

  1. What is the recommended approach to attach mesh to a bone without animation?
  2. When I want to move a character, should I move its mesh or skeleton? The popular lib I use, CharacterController moves it by character, I would have to rewrite it to move its skeleton.
  3. I think I am misunderstanding the parent relationship here, when I move the character, shouldn’t the skeleton move, then the bone, then the attached object?

Similar topic WITH animation:

This one breaks down as soon as you comment out the animation out on line 48, see it here:
www.babylonjs-playground .com/#11BH6Z#717
(new users can’t post more than two links)

Thanks a lot for any help in advance!
-Matus

Hello and welcome to our community!

  1. For performance reason, the system tries to never update something that is cached so flagging the bone as dirty to force that update is a god technique

  2. Moving the mesh should work ;I’m on my phone so I did not check your pg) as long as you are not loading your data from a gltf. If this is the case then you need to figure out which mesh is the skeleton impostor (this is a bit weird to me but gltf will delegate the skeleton animation to a mesh hierarchy).

3.Moving the mesh will only update the mesh world matrix so the system will not need to update the bones (they are all local matrices) so it will update the rendering (gpu will recompute all the matrix multiplications) but no change to the bones on the cpu side)

Hope it helps:)

2 Likes

Hello @Matus just checking in, do you have any more questions about this? :smiley:

2 Likes

Hi Carol,

Thanks for checking up. I ended up flagging the bone as dirty in every code path that moves the character.

Although it still feels like it’s not really attached in the same sense, since the attached bones move when the character moves but the mesh attached to the bone doesn’t. Also in future I need to remember to flag a specific bone as dirty if I try to move the character in different ways, or wrap the logic around some extra class.

I don’t know much about the Babylon internals, it just felt like I was probably doing something wrong.

But if it’s intended behaviour than it’s all good :slight_smile:

1 Like