Animator.GetBoneTransform returns null

GetBoneTransform returns null after upgrading Unity version.

In Unity2018.4.19 it is not null, but in Unity2020.3.8 it returns null.

And the avatar is a prefab object. If it is an object in the scene, it is not null in Unity 2020.

I don’t want to put the avatar object in the scene as much as possible. If you have a good idea, please advise.
Thanks.

public GameObject avatar;

void Start()
{
    Animator anim = this.avatar.GetComponent<Animator>();

    Transform trans = anim.GetBoneTransform(HumanBodyBones.LeftHand);

    if(trans == null){ Debug.LogWarning("LeftHand is null"); }
    else             { Debug.LogWarning("LeftHand is NOT null"); }
}

I ran into this issue myself after upgrading.

For me, the issue appeared to be caused from the Armature’s hierarchy being disabled. I thought this odd as this was not an issue in previous versions. Maybe Unity changed how the call searches the hierarchy?

This call appears to work as expected when the hierarchy is enabled.

Sometimes a bone isnt stored or read the same with diffrent versions, try opening the model in the animator itself to see if it sees the correct bones and positions/animation data then save it from the animator on the new version of unity to make sure its saved in the format that version reads. Sometimes you get this when importing from other programs/assets as well since each editor saves data diffrently in a diffrent format, so often just opening in the built in animator can often fix this in my experience.