• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Apr 20, 2018 at 04:01 PM by Fibonacci_0_1_1 for the following reason:

solved the problem.

avatar image
0
Question by Fibonacci_0_1_1 · Apr 18, 2018 at 11:19 PM · transformhierarchyfindbonesbone

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 () 
     {
         
     }
 }
 





Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fibonacci_0_1_1 · Apr 20, 2018 at 03:56 PM 0
Share

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".

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Priyanka-Rajwanshi · Apr 19, 2018 at 04:15 AM

@Fibonacci_0_1_1 Try:

  player_head = transform.Find("Head");
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fibonacci_0_1_1 · Apr 19, 2018 at 05:13 AM 0
Share

nope didn't work. i dont know why its not working...

avatar image Priyanka-Rajwanshi Fibonacci_0_1_1 · Apr 19, 2018 at 05:45 AM 0
Share

Could you post a screenshot of the complete player hierarchy? Not the avatar configuration

avatar image Fibonacci_0_1_1 Priyanka-Rajwanshi · Apr 19, 2018 at 02:08 PM 0
Share

okay, i just did that. my hierarchy doesn't show bones it just shows the player_model and a child named body.

Show more comments
avatar image
0

Answer by Cornelis-de-Jager · Apr 19, 2018 at 12:03 AM

simply try:

 player_head = GameObject.Find("Head");
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fibonacci_0_1_1 · Apr 19, 2018 at 05:12 AM 0
Share

i tried it, it didn't work.

avatar image MlleBun Fibonacci_0_1_1 · Feb 09, 2020 at 03:00 PM 0
Share

And player_head = GameObject.Find("Head").transform; ?

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

101 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Bone Not Rotating? 1 Answer

transform find with tags always return null 1 Answer

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

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges