How to attach a entity to a bone of a model

I am trying to attach a gun to my ai enemies but I just can’t figure it out. I have looked at a bunch of other forums but I just can’t get it to work.

Hi @Connor_Briggs,

Here is a helpful post on how to debug your issue:

You can also use the new Import Hierarchy option when importing your NPC model. That way you will get the full bones hierarchy and you can easily drag and drop an entity as a child there. That way you can do the same thing without code.


i don’t see that setting in the editor

can you do that to my npc model plz

You can find it here, under your project settings:

thanks i’ll try that

1 Like

can some body make a simple code with the M-16 model attach to the right-hand bone and make it work with animation

You have to enable the Convert to GLB option first to be able to see the Import Hierarchy option.

If you enabled both options and upload your character again, you can see all of the character’s entities in your hierarchy and add another entity to it.

1 Like
var box = new pc.Entity('cube');
    box.addComponent('model', {
    type: 'box'

box.setLocalScale(30, 30, 30);'MaleBaseMesh:Hips').addChild(box);

i am trying to use this code because it works on the animation and doesn’t lag as badly.
problem is it will load if it is a cube but not any of my gun models

I tried the import option and it just crashed again and again

i tried to change the code above it to my gun models and it said it is already parented and when i reparented it,it wouldn’t load the model at all

Did you already tried something like below (based on your current project)?


no sir i haven’t yet

it just says reparent undefinded

Probably because the capital letter.



well no errors but the model isn’t there

That’s good so far. Try to use the solution from the topic below.

I guess ‘weapon’ in that topic should be your character and ‘weaponOutput’ should be your gun.

thanks for the help i’l take a look at the topic below.
If i can’t get it to work i’t talk later (about to leave for sccocer pratice)

1 Like

I will try it myself tomorrow using the full hierarchy, because I think this is much easier for setting the correct scale and rotation.