How do I switch heads with different tracking pose settings in the same scene?

Introduction

This section describes how to switch heads with different tracking pose setting in the same scene when you need to support a different tracking scheme.

If you create two or more heads with different tracking pose setting, the head will get the wrong pose data when you switch them without activating one head and deactivating the others.

With this problem in mind, we came up with a solution and show you how to avoid the problem in the following example.

Example

There are two methods listed below to find the head on the same scene and these methods take advantage of the style of the tracking origin (TrackingUniverseSeated, TrackingUniverseStanding) to switch two heads. The public flag HowToFindHead of ChooseDoF is used to select which find method you want to adopt.

public class ChooseDoF : MonoBehaviour {
        public ETrackingUniverseOrigin trackingSpace = ETrackingUniverseOrigin.TrackingUniverseSeated;
        public bool HowToFindHead = false;
        void OnEnable() {
                if (HowToFindHead)
                        method1();
                else
                        method2();
        }
        // For method 1, it makes use of the Transform function to find the head you would like to take.
        void method1() {
        #if UNITY_5_5_OR_NEWER
                // Global find
                GameObject body1 = transform.root.Find("Body1").gameObject;
                GameObject body2 = transform.root.Find("Body2").gameObject;
        #else
                // Children find
                GameObject body1 = transform.Find("Body1").gameObject;
                GameObject body2 = transform.FindChild("Body2").gameObject;
        #endif
                if (trackingSpace == ETrackingUniverseOrigin.TrackingUniverseSeated)
                        body1.SetActive(true);
                else
                        body2.SetActive(true);
        }
        // For method 2, it traverses the component list to find the head you would like to take.
        void method2() {
                // Children find
                var list = GetComponentsInChildren<WaveVR_Render>(true);

                foreach (WaveVR_Render render in list)
                {
                        var obj = render.transform.parent.gameObject;
                        if (trackingSpace == ETrackingUniverseOrigin.TrackingUniverseSeated)
                        {
                                if (obj.name == "Body1")
                                {
                                        obj.SetActive(true);
                                        break;
                                }
                        }
                        else
                        {
                                if (obj.name == "Body2")
                                {
                                        obj.SetActive(true);
                                        break;
                                }
                        }
                }
        }
}

Before running, all heads are inactive.

_images/twohmd_diff_tracking_inactive.png

If you choose Tracking Universe Seated in Tracking Space, the head ‘body1’ will become active.

_images/twohmd_diff_tracking_method1.png

If you choose Tracking Universe Standing in Tracking Space, the head ‘body2’ will become active.

_images/twohmd_diff_tracking_method2.png