Attaching a Mesh To a Bone(assetsManager.addContainerTask, instantiateModelsToScene)

sword.attachToBone(skeleton.bones[34], character);
assetsManager.addContainerTask("solders", "", "/assets/models/solders.glb").onSuccess = function(task) {
  task.loadedContainer.addAllToScene();
  window.soldersContainer = task.loadedContainer; 
  for (let i = 0; i < task.loadedMeshes.length; i++) {
    if (task.loadedMeshes[i].name.toLowerCase().includes('soldersgun0')) {
      let soldersgun0 = task.loadedMeshes[i];
      soldersgun0.material = window.stormmat;
    }
    //end
  }
}
let solder = window.soldersContainer.instantiateModelsToScene(name => String(`Solder`), false);
//solder.rootNodes[0].getChildren()[2].attachToBone(solder.rootNodes[0].skeletons[0].bones[34], solder.rootNodes[0].getChildren()[0]);

solder.rootNodes[0].getChildren()[2].attachToBone(?, ?);

What should I specify in the parameters to bind a weapon to the character’s hand?

1 Like

You will have to find the real mesh (meaning, not a TransformNode but a Mesh instance) in your scene to which you want to attach the sword. Then, sword.attachToBone(mesh.skeleton.bones[34], mesh) should work. Also, if you can create a repro in the Playground, it will be easier for us to help you.