Preprocessor Directive for Enabling VisionOS XR Rig on a Cross-Platform Quest MR App

Hi there, I’m currently building a cross platform app for Quest 3 and the AVP. It’s a pretty simple app with just hand tracking and some plane classification from the AR Foundation. I’m pretty much at the final stage where I’ve tested the app on both platforms and it works as expected.

However, I’m trying to streamline development for the future through the use of Preprocessor Directives to automatically enable the correct XR rig for either AVP or Quest. I have a script that essentially just does the following. I’ve set it to run on Awake and the script execution order to be the very first. It works for Android, but not visionOS oddly enough. Any thoughts why this might be? Thanks.

    public void Awake()
    {
#if UNITY_VISIONOS
        VisionRig.SetActive(true);
        QuestRig.SetActive(false);
        VisionOSVolumeCam.SetActive(true);
        environmentManager.SetCamTrans(VisionCamTrans);
# elif UNITY_ANDROID
        VisionRig.SetActive(false);
        QuestRig.SetActive(true);
        VisionOSVolumeCam.SetActive(false);
        environmentManager.SetCamTrans(QuestCamTrans);
#endif
    }

Unity Version 2022.3.27f1
Polyspatial Version 1.2.3

1 Like

@Spencer-L Hi, Were you able to find an answer for this and a good workflow?

It’s hard to know what the issue is without more information on your scene setup and XR Plug-in Management settings. Note that Awake order by default is non-deterministic, so it’s possible that one of your “Rig” GameObjects woke up before this script and did some work that it shouldn’t have done.

As one solution, maybe consider Instantiating the prefab at runtime instead, or saving the scene with all prefabs disabled?