I've seen that the bones are Transforms. And i've tried copying many examples. The armature is the standard MakeHuman one and is unchanged. It imported to Unity fine and the mocap animations work perfectly. What I need to do is make the hand a parent of my gun .
Here is what I have currently (I have tried many similar permutations):
Transform handR;
public GameObject gunPrefab;
GameObject gun;
private void Start()
{
rb = GetComponent<Rigidbody>();
playerAnims = GetComponentInChildren<PlayerAnimations>();
absoluteGround = rb.transform.position.y;
distToGround = GetComponent<Collider>().bounds.extents.y;
handR = transform.Find("hand_r");
Debug.Log("handR really is: " + handR);
gun = GameObject.Instantiate(gunPrefab);
gun.transform.SetParent(handR);
//gun.transform.position = handR.position;
gun.transform.rotation = Quaternion.identity;
}
The end result of this: The gun will spawn but isnt parented to anything. And if I try to set its position using handR.position then i get null exception. Pic above shows the image where I see its called "hand_r"
One more thing of note: The bones shown in the image above , do NOT appear in the hierarchy. I have on occasion imported models with the bones included whose bone names all appear in the hierarchy - could this be the reason Unity is finding "hand_r"??? and if so whats the best way to fix that (Please done say remove the armature and make my own in Blender !! :O )
PS: I have since tried it with a new model, made in Blender with a Rigify rig. The code part "handR = transform.Find("hand_R"); -yes the rigify rig names it with capital "R". Still doesnt work, BUT THERE IS A WORKAROUND I FOUND... if I make the Transform handR public and drag it into the Inspector it all works fine! (And yes the Rigify skeleton also shows up in hierarchy!) (So if you are reading this and struggling too, DONT use the MakeHuman skeleton, use one from Blender Rigify.)
But I'm still very confused why the "Find" command doesnt find the bone