Animator.GetBoneTransform() returns null

Hey folks,

we have a rigged character with a humanoid skeleton. Everything is setup correctly and when I switch to the configuration view I can also see that every human body bone has its corresponding Transform.

Now I need to attach another GameObject to one of these bones and since Unity doesn’t allow me to find these bones by using Find() or whatever my idea was to use Animator.GetBoneTransform() to retrieve the bone I need.

But the problem is that this method always returns null, no matter what HumanBodyBones I use.

We tried disabling OptimizeGameObjects and OptimizeMesh for the model importerex but that didn’t help.

Also the ExtraTransformsToExpose list doesn’t expose any Transform so I could use these.

Any suggestions?

You can use GameObject.Find() but this is literally the worst possible solution. If Find() couldn’t even find the bone by name then you’re probably breaking something on your rig/animator/avatar at runtime.

Animator.GetBoneTransform() is the safest way to get a particular bone on a humanoid rig and if the avatar is configured correctly and assigned to the mesh then there is probably something breaking things at runtime or you’re running GetBoneTransform() on the wrong animator.

Maybe post some code or share the model.

I’ve never tried using GetBoneTransform before, but it seems to always be returning null for me as well. I’m positive I have the correct animator referenced and that my Mecanim rigs are configured correctly.

Anyone else running into this? I’m using 2017.1. I’ll try testing with an empty project tonight.

I am also having this problem. The rig is properly imported as Humanoid and I have confirmed that all the transforms that I am requesting are part of the rig. I have double-checked that the animator I am calling is indeed the correct animator. I am using 2018.2.1f1 currently and I’m tempted to try the beta 2018.3

Hi guys, we experience same issue. we have 2 rigs one works perfectly and another with same hierarchy and setup just return null when I call GetBoneTransform(HumanBodyBones.AnyPart)

We are able to find the bones with GamObject.Find() but not with GetBoneTransform()

2018.3.6

4468525--410458--upload_2019-4-25_10-50-58.png

I figured out the issue. If you rename any of the GameObjects in the rigs hierarchy, GetBoneTransform will return null. Make sure to have the names the same as they are in the Avatar component.

Maybe you can change the name(s) but you will also have to update the name changes in the Avatar object aswell.

4 Likes

I was running into this issue today, where GetBoneTransform was always returning null on one of my models. This probably won’t be the reason most will encounter, but I figured I’d mention my issue, and what fixed it for me.

In my case, the issue was that I swapped out a model, but didn’t update the Animator’s avatar. So Unity was trying to use the wrong avatar to find the bones on my new model. This was fixed by making sure that the Animator component on my character was pointing at the correct avatar.

5263736--526604--upload_2019-12-9_15-42-0.png

1 Like

Also please ensure the gameobject with animator is enabled when you call GetBoneTransform.

2 Likes

You can also use transform.Find() in tandem with a known path to the transform you want if you know the exact path to the transform in question.

Its in the unity documentation.

I had the same issue as well. I found my error to be that the avatar I created was Animation type Generic instead of Humanoid. Once I created the new avatar type Humanoid and updated all my animations to use this new avatar, I was able to call GetBoneTransform.

Make sure the avatar type you are using is Humanoid and if not, update it. Hopefully this helps :slight_smile: