Skip to main content
New Participant
August 11, 2021
Solved

Bones list is empty

  • August 11, 2021
  • 1 reply
  • 2283 views

Hi Folks,

 

Two questions:

1. My list of bones is always empty. 

I have an OVRhandprefab stored in a variable called skeleton. But when I call skeleton.Bones in my start method it always has a count of zero. So, I can't get a list of anything. 

(this is from the valem gesture detection tutorial)

 

2. I want to get the position of the tip of the right hand at one point in my code. How do I reference  this? 

 

Thanks

 

    This topic has been closed for replies.
    Best answer by

    You have to wait until the OVRSkeleton's Initialize method has finished before you can get the bones. The simplest way to do that is wait a frame before getting the bones. Since the Start method can be turned into a coroutine you can do that like this:

     

    public class GetBones : MonoBehaviour {
        private OVRSkeleton skeleton;
        private Transform indexTipTransform;
    
        // Start is called before the first frame update
        IEnumerator Start() {
            skeleton = GetComponent<OVRSkeleton>();
    
            while (skeleton.Bones.Count == 0) {
                yield return null;
            }
    
            foreach (var bone in skeleton.Bones) {
                if (bone.Id == OVRSkeleton.BoneId.Hand_IndexTip) {
                    indexTipTransform = bone.Transform;
                }
            }
        }
    }

     

    Then if there's a particular part of the hand to you to get the position of you look for the bone.Id in the Bones list and store that part's transform (the foreach part above).

    1 reply

    Answer
    August 11, 2021

    You have to wait until the OVRSkeleton's Initialize method has finished before you can get the bones. The simplest way to do that is wait a frame before getting the bones. Since the Start method can be turned into a coroutine you can do that like this:

     

    public class GetBones : MonoBehaviour {
        private OVRSkeleton skeleton;
        private Transform indexTipTransform;
    
        // Start is called before the first frame update
        IEnumerator Start() {
            skeleton = GetComponent<OVRSkeleton>();
    
            while (skeleton.Bones.Count == 0) {
                yield return null;
            }
    
            foreach (var bone in skeleton.Bones) {
                if (bone.Id == OVRSkeleton.BoneId.Hand_IndexTip) {
                    indexTipTransform = bone.Transform;
                }
            }
        }
    }

     

    Then if there's a particular part of the hand to you to get the position of you look for the bone.Id in the Bones list and store that part's transform (the foreach part above).