Attach hat to a model's head?

Kyv'thil'hurum

L1: Registered
Jul 23, 2013
14
2
I have a prop_dynamic Spy and a prop_dynamic Hat of Cards in my map. I want to attach the hat to the Spy's head, as if the Spy had the hat equipped... but I have no idea how to do this. The closest I've gotten is using a logic_auto to SetParentAttachment to eyes when the map starts... but this spawns the hat in the middle of the Spy's face. I tried SetParentAttachment to bip_head based on modeling tutorials I've read, but the console gave me this error...

ERROR: Tried to SetParentAttachment for entity prop_dynamic (spy_hat), but it has no attachment named bip_head.

...and the hat just appeared on the floor next to the Spy, like I had placed it in Hammer.

Does anyone know how to do this properly?
 

DonutVikingChap

L5: Dapper Member
Mar 15, 2013
233
139
1. Make a point_template called spy_template or something like that.
2. Add the spy and the hat to Template 1 and 2 respectively.
3. Add this output to your logic_auto: OnMapSpawn > spy_template > ForceSpawn (Delay: 0.00)
4. Add these outputs to your point_template:
  • OnEntitySpawned > hat > SetParent > spy (Delay: 0.20)
  • OnEntitySpawned > hat > SetParentAttachmentMaintainOffset > bone_name_here (Delay: 0.50)
  • OnEntitySpawned > spy > SetAnimation > whatever (Delay: 1.00)

And it should work!


NOTE:
  • The delays don't need those specific timings, just make sure you do them in that order.
  • You have to place the hat manually in the correct position on top of the spy's head in hammer, not on the ground.
  • The point_template is optional (I think), but it makes for better organization.
  • I don't know what is the correct bone name to use, but the eyes might work fine.
  • There might be a better way to do this, but it works.
 

Kyv'thil'hurum

L1: Registered
Jul 23, 2013
14
2
1. Make a point_template called spy_template or something like that.
2. Add the spy and the hat to Template 1 and 2 respectively.
3. Add this output to your logic_auto: OnMapSpawn > spy_template > ForceSpawn (Delay: 0.00)
4. Add these outputs to your point_template:
  • OnEntitySpawned > hat > SetParent > spy (Delay: 0.20)
  • OnEntitySpawned > hat > SetParentAttachmentMaintainOffset > bone_name_here (Delay: 0.50)
  • OnEntitySpawned > spy > SetAnimation > whatever (Delay: 1.00)

And it should work!


NOTE:
  • The delays don't need those specific timings, just make sure you do them in that order.
  • You have to place the hat manually in the correct position on top of the spy's head in hammer, not on the ground.
  • The point_template is optional (I think), but it makes for better organization.
  • I don't know what is the correct bone name to use, but the eyes might work fine.
  • There might be a better way to do this, but it works.

This is roughly the same thing I was doing (I didn't have the point_template), but I didn't realize you needed to manually place the hat on the head. I think this is because I used SetParentAttachment which forced the origin of the hat directly to the "eyes" attachment area, whereas SetParentAttachmentMaintainOffset seems to attach the hat to that attachment point while not moving the hat itself (Similar to the difference between Welding and Easy Welding, for anyone who has played GMOD). Placing the hat on the head correctly is a bit of a pain and I don't think I have it on quite right, but this does work. Thanks for the help. c:

Does anyone know of a different attachment point I should be using? "eyes" doesn't seem like the right one, because it's roughly in the center of the head.
 
Last edited: