Deprecation nightmare

So…

In some asset I bought on the asset store, it checks for wether VR is active or not using

PlayerSettings.virtualRealitySupported

So I get this :

So I try to find it, but typing XRManagerSettings. doesn’t get me anything. Ok, fine, I search a bit and find this :

UnityEngine.XR.XRSettings.enabled = true;

But hey, no, it’s deprecated again !

5389734--546552--Sans titre.png

Let’s find it then, it’s in UnityEngine.XR.XRDisplaySubsystem
But there is no public accessor of anything.

No documentation, (even things that are derecated are not taged as such on the doc).

WHERE can I find what I’m looking for ?

5 Likes

Hi @Jichaels ,

Did you check Unity - Scripting API: XRSettings
(Or some of the other XR classes that are nearby in the documentation.)

Yes, and for exemple this : Unity - Scripting API: XR.XRSettings.enabled (the second thing I tried) is deprecated, even if it’s not written anywhere

Those APIs are deprecated in 2019.3+ but are still usable in 2019. The warnings are there to make sure that users are aware that they are not going to be available for 2020+ and are being replaced with the new XR Plugin model ( XR Plugins and Subsystems ).

That said, your question is a bit unclear. What is it you are trying to find?

1 Like

I have submitted a bug regarding this topic as well (case 1213569). /cc @joejo

We need to check if VR is enabled (in any form). Problem is, if XR manager package is not installed, there’s no way to check this and any editor extension asset testing whether VR is enabled or not, will fail.
In this case, we’re not using any XR functionality. We just need to know if XR is enabled like the PlayerSettings.virtualRealitySupported API did.

1 Like

That API is usable and supported in 2019.3. The warning is just a warning about future support post 2019.

Thank you. I get it, but the warning is annoying and triggers user questions. The issue is, what will happen when the API is removed? How can we have editor scripts that checks if VR is enabled without requiring (obviously) the installation of a VR package?

If VR packages aren’t installed, VR won’t be enabled. Every things in the new XR Plugins systems is based on packages and not on core Unity.

If you want to check if any VR is running at all you can check if an instance of any Display Subsystem is running at all:

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;

public class VRStatus : MonoBehaviour
{
    List<XRDisplaySubsystemDescriptor> displaysDescs = new List<XRDisplaySubsystemDescriptor>();
    List<XRDisplaySubsystem> displays = new List<XRDisplaySubsystem>();

    bool IsActive()
    {
        displaysDescs.Clear();
        SubsystemManager.GetSubsystemDescriptors(displaysDescs);

        // If there are registered display descriptors that is a good indication that VR is most likely "enabled"
        return displaysDescs.Length > 0;
    }

    bool IsVrRunning()
    {
        bool vrIsRunning = false;
        displays.Clear()
        SubsystemManager.GetInstances(displays);
        foreach (var displaySubsystem in displays)
        {
            if (displaySubsystem.running)
            {
                vrIsRunning = true;
                break;
            }
        }

        return vrIsRunning;
    }

}

Relevant docs:

Subsystem in general: Unity - Scripting API: UnityEngine.SubsystemsModule
XR Subsystem Module: Unity - Scripting API: UnityEngine.XRModule
Up to date XR Management package documentation: Redirecting to latest version of com.unity.xr.management

4 Likes

Thanks so much!

1 Like

Thanks for the answers. I’m actually working on a project that is usable both VR/Non VR and can swap at runtime using userPresence (eg. put the hmd on, it activate VR, remove it, you go back to non vr).

The thing is, to be able to switch between both I have to do a bunch of things, and even when it’s not VR, it is still activated. I just wanted a way to make it easier.

I found this because I just bought an asset (HighlightPlus) that have an editor script that check if VR is enabled or not, which is always the case in my project even if we are on “non vr” mode.

Thanks for your reply

2 Likes

@joejo I wonder, in order to make the transition smoother, if PlayerSettings.virtualRealitySupported could be replaced by the API importer to SystemInfo.virtualRealitySupported assuming that new method implements the code you posted above.

Can anyone point me to relivent documentaiton on this
I am trying to figure out how to enable XR at runtime and disbale it at run time much like the OP was after yet between all the ‘chase down the depricated features’ and multiple bits of documetnaiton that dont seem to reflect what I see in Unity I have not been able to figure it out.

XRSettings.enable throws deprication warnings … which it should not due until its actually depricated. This idea of adding deprication warnings in before the feature is actually depricated causes a lot of issues please stop if that is what you are doing. Depricated… means its depricated now to most people you see this same issue with uNET when it was being depricated and many other features.

I have used the code listed above to see if active and if running and that worked … thank you for that … please add it as a code example in your documentation

I however cannot figure out how to start an XrDisplaySubsystem, displays list from the above is always count == 0 and trying to call XRSettings.LoadDeviceByName(XRSettings.supportedDevices); just gives deprication warnings telling me to use SubsystemManager which I dont see anyway to load anything with that.

For the new XR Plugin system, you can follow along with what is here: toggle between 2d and Google Cardboard - Unity Engine - Unity Discussions

And note that the code sample there will be in the updated docs for XR Plug-in Management 3.2.12, which should be out soon.

And note that, if you are using the new XR Plug-in system, you shouldn’t be using the old XRDevice/XRSettings APIs.

General information on the system can be fouhnd here: Unity - Manual: XR architecture

For manually controlling the display subsystem you can see documentation on that here: Unity - Scripting API: XRDisplaySubsystem

With general docs on all ISubsystem implementations here: Unity - Scripting API: ISubsystem

Thanks JoeJo

I think I am stumbling through at least with basic manipulation of the system. The issue I am looking at now is stacked cameras, I haven’t found anything yet that says it doesn’t work but from what I can see … it doesn’t work. Have i missed something or is overlay simply not supported at the moment?

Hi @Loden_Heathen_1 ,

Stacked camera should work. Do you mind to share more information about your project? Which render pipeline you were using for your project? URP or built-in render pipe?

For 19.3, URP XR camera stack is supported for singlepass instanced mode and multiview mode. Multipass mode camera stack is not supported yet.
URP camera stack documentation is here: Camera Stacking | Universal RP | 7.4.3

Please note in 19.3, Vulkan API is experimental for URP Quest, we recommend GLES for stability if you are targeting Oculus Quest device.

Thanks,
Thomas

URP and camera stacking works as expected … untill we initalize XR display and then its a mess.
The base camera doesn’t render at all only 1 overlay camera renders and which one seems to be a guessing game and it only renders to 1 eye. Now if we go single camera it works as expected.

For note we are using Windows Mixed Reality at the moment for testing and having tons of issues … for example the head set tracks fine using the Track Pose componenet but the controllers do not. I have gotten the
InputDevices.GetDeviceAtXRNode
to work (return the device) for left and right hand but
device.TryGetFeatureValue(CommonUsages.devicePosition, out position)
returns false e.g. cant get position or rotaiton manually and as noted the Track Pose componenet just doesn’t work at all for the controllers.

Since we are having so many issues we have just droped the idea of multiple cameras for now and are struggling to get the controllers to track. Got to say, we built a few simple VR apps on Unity; god years ago at this point using the DK2 Dev kit (really early days) and it was far far easier to get going than Unity XR has been so far. I like the idea of it but its really hard to find accurate information. Documentation doesn’t line up with what we see in code, cant find code examples that work either and poking at it till it works is a bunch of running into depricated messages and bits like finding the device using GetDeviceAtXRNode … for the left hand and then that device not having postion and rotaiton???

Just to be sure its not just my bone headed coding … which 20 years software engineering I would have thought I could get it … but I did go ahead and pull a few VR assets off the store to see what they where doing, if they would work … and no … they are doing very similar to what I am trying and it does not work.

I assume its a code problem since somethings work and some things dont but with broken docs and no code samples + the depricated code in the engine its a real strugle to figure out by pokeing at it.

[[Edit]]
device = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
Is returning an invalid device … sware it was valid before but fine that at least explains why I cant get positon … but when I iterate over my devices I do see 3 being the headset and left and right controllers … so what gives?

[[Edit]]
Okay I managed to get my devices reasonably reliably
To do so I get all instances of XRInputSubsystem … even though there should onyl be 3 this is returning 7. Its returning 3 sets of the hand controlls … not sure whats going on with that.

Any way once you have that you can loop through the inputs and get the devices for that input. Next you need to test if it has the right flags e.g. HeldInHand, TrackedDevice and Left or Right.

So to make that simpler I added 3 InputDevice fields to our SystemSettings … its just a ScriptableObject that gets intialized on bootstrap of the game. Within that I have a bit of code that looks like the following

var inputs = new List<XRInputSubsystem>();
            SubsystemManager.GetInstances(inputs);
            bool canTest = false;
            bool result = false;
            if (inputs.Count > 0)
            {
                List<InputDevice> devices = new List<InputDevice>();
                foreach (var input in inputs)
                {
                    if (input.TryGetInputDevices(devices))
                    {
                        foreach (var d in devices)
                        {
                            if ((d.characteristics & (InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Left)) == (InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Left))
                                leftHandInput = d;
                            if ((d.characteristics & (InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Right)) == (InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Right))
                                rightHandInput = d;
                            if ((d.characteristics & (InputDeviceCharacteristics.HeadMounted | InputDeviceCharacteristics.TrackedDevice)) == (InputDeviceCharacteristics.HeadMounted | InputDeviceCharacteristics.TrackedDevice))
                                headSetInput = d;

                            if (d.TryGetFeatureValue(CommonUsages.userPresence, out bool userPresent))
                            {
                                canTest = true;
                                if (userPresent)
                                    result = true;
                            }
                        }
                    }
                }
            }

That is hackish and messy and there must be a better way of doing it but so far this is the only thing that has worked to get the device of the hand controllers so I can set position.

1 Like

I think I liked UnityEngine.XRSettings.enabled = true; more.

Why is everything such a horrible, complicated mess?

1 Like

where is depreciated settings? using 2021.3