Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
omtron's avatar
omtron
Protege
9 years ago

Trying to get a finger transform

I need a reference to a finger's transform to track its movement. I'm having a hard time grabbing it since it initializes at runtime and is not always active (therefore GameObject.Find("...") won't find it). Is there a reference to the fingers somewhere?

3 Replies

Replies have been turned off for this discussion
  • Here is the solution I found. It's inefficient but I can't think of a better way and it only runs one frame anyway:

    At OvrAvatar.cs at end of AddAvatarComponent, added:

            if (componentObject.name == "hand_right")
                GetFingerTips(componentObject);
            else if (componentObject.name == "hand_left")
                GetFingerTips(componentObject);

    Then create a method in OvrAvatar.cs:

        private void GetFingerTips(GameObject obj)
        {
            Transform[] children = obj.transform.GetComponentsInChildren<Transform>(true);
            foreach (Transform child in children)
            {
                if (child.name == "hands:b_l_middle_ignore")
                {
                    TouchManager.touchManager.leftMiddleFingerTip = child;
                }
                else if (child.name == "hands:b_r_middle_ignore")
                {
                    TouchManager.touchManager.rightMiddleFingerTip = child;
                }
            }
        }

  • Yeah I do a similar thing to find the wrist joint..just manually step down children 3 times.
    Not amazing but works


    -P
  • I may have found a more elegant way to do this.

    What I have done is in my Start() I add a listener to the AssetsDoneLoading event. After which, I get the OvrAvatarComponent and recurse through the children until I find what I am looking for.

    Of course don't forget to Remove your listener.

    void Start()
    {
        OvrAvatar ovAdv = transform.GetComponent<OvrAvatar>();
        ovAdv.AssetsDoneLoading.AddListener(Find);
    }

    void Find()
    {
        OvrAvatarComponent ovrCom = (rHand.GetComponent("OvrAvatarComponent") as OvrAvatarComponent);
        indexFingerBone = Recurse(ovrCom.transform, "hands:b_r_index1");
    }

    Transform Recurse(Transform t, string find)
    {
        Transform rtn = null;

        for (int x = 0; x < t.childCount; x++)
        {

            if (t.GetChild(x).name == find)
            {
                rtn = t.GetChild(x);
                break;
            }
            if (t.GetChild(x).childCount != 0)
                rtn = Recurse(t.GetChild(x), find);
        }

        return rtn;
    }