ultimatexr-unity icon indicating copy to clipboard operation
ultimatexr-unity copied to clipboard

[0.8.2][Feature Request] Support "Disabled Domain Reloading" to allow for quickly entering Play Mode

Open CyanLaser opened this issue 2 years ago • 1 comments

Background info

By default, entering Play Mode will reload all assembly domains, which takes time depending on the project. Unity provides editor settings to disable domain reloading, which will reduce the time to enter Play Mode allowing for rapid iteration. Code must be written to properly support this. When domain reloading is disabled, static variables will keep their values after exiting Play Mode.

Problem

UltimateXR does not currently support disabling Domain Reloading. Entering Play Mode after the first time does not properly initialize any singleton managers. From my quick test, it appears that one issue is due to the use of is null on Unity Objects. https://github.com/VRMADA/ultimatexr-unity/blob/a97a7026cde6d0bfb8ea7d0ea8dc18d40e8b1bc4/Scripts/Core/Components/Singleton/UxrSingleton.cs#L62

Destroying any type that extends UnityEngine.Object will treat this object as null for any UnityEngine.Object comparisons methods. The problem is that the object itself will still exist. Casting it to System.object will give different results, saying the object is not null.

Potential Solutions

Option 1

Changing usage of is null to == null in UxrSingleton.cs and UxrAbstractSingleton.cs solved the issue for me. Although, I am not familiar enough with the codebase to know if these two files are the only ones that need the change nor do I know the implications of how the rest of the code will handle this small difference.

Option 2

UxrAbstractSingleton appears to handle releasing the singleton when the object is destroyed. From my test in editor using the provided example scene, no singleton instances are ever set to null. Verifying the Editor Exit Play Mode case properly sets singletons to null may also fix this without changing any null comparisons.

CyanLaser avatar Aug 05 '22 14:08 CyanLaser

Thank you for your detailed description. I will look into this and check if there are any other implications.

entromp avatar Aug 06 '22 09:08 entromp