Skip to main content
Inspiring
January 7, 2017

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?
This topic has been closed for replies.

3 replies

omtronAuthor
Inspiring
January 7, 2017
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;
            }
        }
    }

Inspiring
January 8, 2017
Yeah I do a similar thing to find the wrist joint..just manually step down children 3 times.
Not amazing but works


-P
Drift VFX Visual, Virtual , Vertical Want 970GTX on Macbook for good FPS? https://forums.oculus.com/viewtopic.php?f=26&t=17349
New Participant
February 7, 2017
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;
}