Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
gary.frewin's avatar
gary.frewin
Explorer
5 years ago
Solved

Bones list is empty

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

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    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

Replies have been turned off for this discussion
  • Anonymous's avatar
    Anonymous

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