Importing a model to PC with the bones from blender and animating the floating arms with the gun

Hello, i’m trying to animate the gun with the floating arms but i want them to be separate entities. I rigged a model and added it a idol pistol animation then i removed the arms from the body on blender. Then i added a bone to the pistol and attached that bone to the arms. Now the pistol moves with the arms. The problem i’m having is, i want to import the arms and the pistol to PC as separate FBX files but i want to animate them just as it works in blender. I was told to enable the import hierarchy box in the PC settings but when i do that, i can’t drag the glb file to hierarchy. I think i may be exporting the models wrong in a wrong way in blender. This is how they look like:

What am i doing wrong here?

1 Like

If you enable import hierarchy, you use the generated template file, and not the glb file. The template file contains the hierarchy.

1 Like

ok i added the arms and the pistol templates separetely to hierarchy. Then i added animation(legacy) component to the arms and dragged an animation file, but it didn’t work

How should i add the animation?

1 Like

Animation (Legacy) only works with Model (Legacy)

Please refer to the following tutorials for using the Anim and Render components with FBX models

https://developer.playcanvas.com/en/tutorials/importing-first-model-and-animation/
https://developer.playcanvas.com/en/tutorials/anim-blending/

1 Like

Ok, it works, thx a lot. Another question, i want to enlarge the object, should i scale the template or just the mesh?

I personally would have the template instance under parent entity and use that parent for resizing, logic scripts etc

1 Like

I imported the pistol as a separate object and followed the same process as i did to the arms but pistol is not moving with the arms during animation. I attached the bone of the gun with the right hand bone of the arms and the pistol was moving with the arms in blender. How can i do the same in Play Canvas?

do i need to merge the arms and the pistol into one object then import them into PC? I’ll try to export the collection this time

1 Like

Have you attached the gun as a child of the correct bone in your arm hierarchy?

If you are still stuck, best to post the project for other people to take a look

yes i did. when i hit the play button, pistol moves with the arms. I can send the blender file too. I tried importing the collection as well, still no luck

Just post the PlayCanvas project is fine

https://playcanvas.com/editor/scene/1528185

the imported blender collection is in the arms folder. arm and pistol model is both there

you’ll see another arms in t-pose in the scene that’s not the one we’re working on right now. the template named arms in hierarchy, that’s the one

Looking at the animation file, where you’ve attached the pistol, it isn’t being animated. The bone is staying completely still.

1 Like

then i didn’t export it right on blender, that might be the reason

what could be the reason that the pistol moves in blender but not in PC?

Looking at the FBX directly from Autodesk FBX Review tool, it looks like the animation for the pistol bone was not exported from Blender to FBX

See this video on how I debug animation issues:

how can i attach the pistol to the hand here?

Ok i figured it out. All i needed to do was making pistol, the child of the hand bone i want it to attach to in Play Canvas. I found it out thx to this post: “How to attach a entity to a bone of a model” and with a friend’s advice

Hey @Ronin if you need a script that attaches a gun to a bone here is the script I am using…

PlayerAnimationHandler.attributes.add('Reparent', {
    type: 'entity'
});
PlayerAnimationHandler.prototype.initialize = function () {
    console.log(this.entity.model.model.skinInstances);
    var base = this.Reparent;
//attach to bone
    base.reparent(this.app.root.findByName('insert bone name here'));
//the size of gun
    base.setLocalScale(1,1,1);
};