How do I make Model follow hand like weapon from MakeHuman? [SOLVED]

I did research to find a answer but none helped. My model is exported from MakeHuman and when I try to attack to a hand model I cannot seem to find it as it only gives me a mesh when I look at hands. I also tried scriptting it in but I keep getting errors.
Script(c#);

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Wrench : MonoBehaviour {
    // Use this for initialization
    void Start () {
      
    }
  
    // Update is called once per frame
    void Update () {
      


    foreach (Transform joint in hierarchy)
             {
                 if (joint.name == "RHandAttachPoint")
                 {
                     Debug.Log("found the attach point anyways");
                     //add the item
                     this.transform.position = joint.transform.position;
                     this.transform.rotation = joint.transform.rotation;
                     this.transform.parent =  joint;
                     return;
                 }
             }  
    }

}

Error I get:

error CS0103: The name `hierarchy' does not exist in the current context\

I found no awnsers for that either. :frowning:

Please help…

[SOLVED!]

In this I have used the script to figure out if the problem is scripting so I am not 100% sure if it is the script that fixed it but I also put the Model into the Hand_r which I had too look through under:
GameEngine > Root > Pelvis > Spine_01 > Spine_02 > Spine_03 > Calvical_r > Upperarm_r > Lowerarm_r > Hand_r (Drop model into this by dropping it onto the word Hand_r)

The error is pretty straightforward… ‘hierarchy’ is not a valid property. Replace it with ‘transform’.

“hierachy” means nothing in the scope you are working, you could type “zxyoiuqwe” and get same compilation error.

You are trying to get the hand joint from your human model, and you are trying to do that from the script attached to your wrench, that’s fine but the wrench script has no concept of the human model.

If you want to bind the wrench to the human from within the wrench script then you need to first get a reference to the human model in the scene.

One way to do that is to add a scene tag to your human model prefab or scene instance of it.

In this example we will tag it “PLAYER”.
In this example you will need to type in your full joint heirachy to replace mine.

                GameObject oHuman = GameObject.FindGameObjectWithTag("PLAYER");
                if(!oPlayer)
                {
                    UnityEngine.Debug.LogWarning("CANT GET: PLAYER");
                    return;
                }

                string sJoint = "skeleton_pilot/sho_l/arm_l/hand_l";
                Transform tHand = oPlayer.transform.Find(sJoint);
                if (!tHand)
                {
                    UnityEngine.Debug.LogWarning("CANT GET JOINT " + sJoint);
                    LOGW("CANT GET " + sJoint);
                    return;
                }

                this.transform.SetPositionAndRotation(tHand.position, tHand.rotation);
                this.transform.parent = tHand;

Also you should not do that in update, update happens every frame, you only need do it in Start or Awake of the wrench, or using some public function from elsewhere if you want the wrench to exist in the scene and then be able to pick it up or drop it .

1 Like

I get this error:
error CS0103: The name `LOGW’ does not exist in the current context

Another thing:
CANT GET JOINT hand_r

Woops, delete the line with LOGW, that’s a special func I use for easy logging.

so yeah, you’re gonna have to replace this:

“skeleton_pilot/sho_l/arm_l/hand_l”

with the full heirachy path to your models hand transform.

to find the full heirachy, put your human model in the scene, then look in scene explorer panel, expand the human heirachy to find all the skeleton joints and then make a note of the full path to the hand. This path may be quite long and you’ve got to be careful of typos.

Well the fact that you got that far means you are succesfully grabbing your tagged human model, so you know how to do that from anywhere in script now.

You could also use the method in your OP to find the joint, it just takes a few more microseconds.
Code for that is:

    //    GET HUMAN MODEL
    GameObject oHuman = GameObject.FindGameObjectWithTag("PLAYER");
    if(!oPlayer)
    {
        Debug.LogWarning("CANT GET: PLAYER");
        return;
    }

    //    LOOK FOR BIND JOINT
    string sJoint = "RHandAttachPoint";
    foreach (Transform joint in oHuman.transform)
    {
        if (joint.name == sJoint)
        {
            Debug.Log("found the attach point anyways");
            //add the item
            this.transform.SetPositionAndRotation(joint.transform.position, joint.transform.rotation);
            this.transform.parent = joint;
            //    GOOD BIND
            return;
        }
    } 
   
    //    BAD BIND
    Debug.LogWarning("CANT FIND JOINT " + sJoint);