Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to programmatically equip weapons to bones in a character?

Discussion in 'Game Design' started by Maximilious, Feb 12, 2018.

  1. Maximilious

    Maximilious

    Joined:
    Nov 29, 2016
    Posts:
    28
    Hello,

    I am currently using the latest UMA2 release from their github. I been trying to follow guides on youtube on how to equip/attach items to bones in unity, but all of them require me to have the root/bones at editor... My UMA characters only have their bones at runtime and I have been able to equip items by just dropping a weapon into the correct bone object (LeftHandFinger03_03) but I cannot do this on the edit so I need to do it with code.

    The complete path of the bone is (this is what appear as a child on my UMA character)
    Root/Global/Position/Hips/LowerBack/Spine/Spine1/LeftShoulder/LeftArm/LeftHand/LeftHandFinger03_03

    Is there anyway for me to access this bone and then add weapons to it in runtime? how can I go about doing this?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    You call transform.SetParent on the weapon transform, and give it the attachment point you want it to be under.
     
  3. WePrompt

    WePrompt

    Joined:
    Jun 27, 2014
    Posts:
    5
    I'm new to uma. Just wondering is there any functions in uma library could help us access uma body part at runtime?
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    There's Animator.GetBoneTransform(...) that takes humanoid bones (if avatar is set to the humanoid).
    Note that I still highly recommend presetting the transform via custom script.
    You can preserve the hierarchy with UMA, if name match 1 to 1. And simply attach another transform as a "weapon slot".

    Also, note that this is wrong sub-forum, you'll get better response ratio @ UMA official thread.
     
  5. unity_W6tp-2Uq_R-_Ig

    unity_W6tp-2Uq_R-_Ig

    Joined:
    Aug 27, 2020
    Posts:
    2
    for those looking for an answer i was having this issue earlier, simply right-click your UMA in Hierarchy - UMA - Create Rig using Bone Builder