- Home /
solved the problem.
How do i find a bone on my character within a script?
Ive been trying to reference the "Head" bone on my character object but when i play the game it says "Cant Find HEAD" instead of "Found HEAD".
I've tried changing the path names and it doesn't seem to do anything, I've also tried changing the object of which the script is placed on but that hasn't changed anything either.
I've noticed that the bones are not shown in the hierarchy tab but they are shown only when i go into the configure option of inspector. does this have something to do with not finding the bone?
any help is greatly appreciated !
!!! ANSWER !!! Okay, I found out what was wrong. as @Priyanka-Rajwanshi explained, the above code would work only if the bone is shown within the hierarchy. Since I have "Optimize Game Objects" active on my player model's Rig, I had to add which bones I could control (add to the hierarchy) under "Extra Transforms to Control".
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class head_rotation : MonoBehaviour {
private Transform head;
void Start ()
{
head = transform.Find("Head");
if (head)
{
Debug.Log("Found HEAD");
}
else
{
Debug.Log("Cant Find HEAD");
}
}
void Update ()
{
}
}
Okay, I found out what was wrong. the above code would work only if the bone is shown within the hierarchy. Since I have Optimize Game Objects active on my player model's Rig, I had to add which bones I could control under "Extra Transforms to Control".
Answer by Priyanka-Rajwanshi · Apr 19, 2018 at 04:15 AM
@Fibonacci_0_1_1 Try:
player_head = transform.Find("Head");
nope didn't work. i dont know why its not working...
Could you post a screenshot of the complete player hierarchy? Not the avatar configuration
okay, i just did that. my hierarchy doesn't show bones it just shows the player_model and a child named body.
Answer by Cornelis-de-Jager · Apr 19, 2018 at 12:03 AM
simply try:
player_head = GameObject.Find("Head");
And player_head = GameObject.Find("Head").transform;
?
Follow this Question
Related Questions
transform.Find always returns null 1 Answer
Free Move Bone On Rigged Object 0 Answers
How to get a recursive named bone transform? 3 Answers
Move armature bones in scene Hierarchy 1 Answer
Bone Not Rotating? 1 Answer