Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Deprecation nightmare

Discussion in 'AR/VR (XR) Discussion' started by Jichaels, Jan 20, 2020.

  1. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    So...

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

    Code (CSharp):
    1. PlayerSettings.virtualRealitySupported
    So I get this :
    Sans titre.png

    So I try to find it, but typing
    Code (CSharp):
    1. XRManagerSettings.
    doesn't get me anything. Ok, fine, I search a bit and find this :

    Code (CSharp):
    1. UnityEngine.XR.XRSettings.enabled = true;
    But hey, no, it's deprecated again !

    Sans titre.png

    Let's find it then, it's in
    Code (CSharp):
    1. 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 ?
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
  3. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
  4. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    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 (https://forum.unity.com/threads/xr-plugins-and-subsystems.693463/).

    That said, your question is a bit unclear. What is it you are trying to find?
     
    soleron likes this.
  5. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,877
    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.
     
    arufolo likes this.
  6. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    That API is usable and supported in 2019.3. The warning is just a warning about future support post 2019.
     
  7. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,877
    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?
     
  8. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    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:

    Code (CSharp):
    1.  
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.XR;
    5.  
    6. public class VRStatus : MonoBehaviour
    7. {
    8.     List<XRDisplaySubsystemDescriptor> displaysDescs = new List<XRDisplaySubsystemDescriptor>();
    9.     List<XRDisplaySubsystem> displays = new List<XRDisplaySubsystem>();
    10.  
    11.     bool IsActive()
    12.     {
    13.         displaysDescs.Clear();
    14.         SubsystemManager.GetSubsystemDescriptors(displaysDescs);
    15.  
    16.         // If there are registered display descriptors that is a good indication that VR is most likely "enabled"
    17.         return displaysDescs.Length > 0;
    18.     }
    19.  
    20.     bool IsVrRunning()
    21.     {
    22.         bool vrIsRunning = false;
    23.         displays.Clear()
    24.         SubsystemManager.GetInstances(displays);
    25.         foreach (var displaySubsystem in displays)
    26.         {
    27.             if (displaySubsystem.running)
    28.             {
    29.                 vrIsRunning = true;
    30.                 break;
    31.             }
    32.         }
    33.  
    34.         return vrIsRunning;
    35.     }
    36.  
    37. }
    38.  
    39.  
    Relevant docs:

    Subsystem in general: https://docs.unity3d.com/2019.3/Documentation/ScriptReference/UnityEngine.SubsystemsModule.html
    XR Subsystem Module: https://docs.unity3d.com/2019.3/Documentation/ScriptReference/UnityEngine.XRModule.html
    Up to date XR Management package documentation: https://docs.unity3d.com/Packages/com.unity.xr.management@latest
     
  9. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,877
    Thanks so much!
     
    ModLunar likes this.
  10. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    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
     
    AlanMattano and arufolo like this.
  11. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,877
    @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.
     
  12. Loden_Heathen

    Loden_Heathen

    Joined:
    Sep 1, 2012
    Posts:
    456
    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.
     
  13. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
  14. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    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: https://docs.unity3d.com/Manual/XRPluginArchitecture.html

    For manually controlling the display subsystem you can see documentation on that here: https://docs.unity3d.com/ScriptReference/XR.XRDisplaySubsystem.html

    With general docs on all ISubsystem implementations here: https://docs.unity3d.com/ScriptReference/ISubsystem.html
     
  15. Loden_Heathen

    Loden_Heathen

    Joined:
    Sep 1, 2012
    Posts:
    456
    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?
     
  16. ThomasZeng

    ThomasZeng

    Unity Technologies

    Joined:
    Jun 24, 2019
    Posts:
    78
    Hi @lodendsg,

    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: https://docs.unity3d.com/Packages/c...nes.universal@7.4/manual/camera-stacking.html

    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
     
  17. Loden_Heathen

    Loden_Heathen

    Joined:
    Sep 1, 2012
    Posts:
    456
    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

    Code (CSharp):
    1. var inputs = new List<XRInputSubsystem>();
    2.             SubsystemManager.GetInstances(inputs);
    3.             bool canTest = false;
    4.             bool result = false;
    5.             if (inputs.Count > 0)
    6.             {
    7.                 List<InputDevice> devices = new List<InputDevice>();
    8.                 foreach (var input in inputs)
    9.                 {
    10.                     if (input.TryGetInputDevices(devices))
    11.                     {
    12.                         foreach (var d in devices)
    13.                         {
    14.                             if ((d.characteristics & (InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Left)) == (InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Left))
    15.                                 leftHandInput = d;
    16.                             if ((d.characteristics & (InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Right)) == (InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Right))
    17.                                 rightHandInput = d;
    18.                             if ((d.characteristics & (InputDeviceCharacteristics.HeadMounted | InputDeviceCharacteristics.TrackedDevice)) == (InputDeviceCharacteristics.HeadMounted | InputDeviceCharacteristics.TrackedDevice))
    19.                                 headSetInput = d;
    20.  
    21.                             if (d.TryGetFeatureValue(CommonUsages.userPresence, out bool userPresent))
    22.                             {
    23.                                 canTest = true;
    24.                                 if (userPresent)
    25.                                     result = true;
    26.                             }
    27.                         }
    28.                     }
    29.                 }
    30.             }
    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.
     
    Last edited: Jun 11, 2020
    AlanMattano likes this.
  18. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    I think I liked UnityEngine.XRSettings.enabled = true; more.

    Why is everything such a horrible, complicated mess?
     
  19. estoyfrito

    estoyfrito

    Joined:
    May 26, 2018
    Posts:
    5
    where is depreciated settings? using 2021.3