Unity report error CS0619: ‘XRDevice.isPresent’ is obsolete

Unity error resolution error cs0619: ‘xrdevice. Ispresent’ is obsolete:

1. Problem description 2. Solution

1. Problem description

Assets\Battlehub\RTCommon\Scripts\RTEBase.cs(690,20): error CS0619: ‘XRDevice.isPresent’ is obsolete: ‘This is obsolete, and should no longer be used. Instead, find the active XRDisplaySubsystem and check that the running property is true (for details, see XRDevice.isPresent documentation).’

This error occurred when I was using unity’s runtimes editor plug-in, which probably means that the API has expired and needs to be modified.


2. Solutions

I checked the Internet and found no relevant information, so I went directly to unity’s API document according to the error message. After looking at it, I know that the previous interface can’t be used. Just rewrite it. Xrdevice.ispresent document. Just rewrite an inner class and call it again according to the document
add the following part to the code, and then modify the calling code.

internal static class ExampleUtil
{
    public static bool isPresent()
    {
        var xrDisplaySubsystems = new List<XRDisplaySubsystem>();
        SubsystemManager.GetInstances<XRDisplaySubsystem>(xrDisplaySubsystems);
        foreach (var xrDisplay in xrDisplaySubsystems)
        {
            if (xrDisplay.running)
            {
                return true;
            }
        }
        return false;
    }
}

Read More: