Search Unity

Resolved XR Plugin Unload

Discussion in 'VR' started by ForrestSmithFRL, Dec 18, 2020.

  1. ForrestSmithFRL

    ForrestSmithFRL

    Joined:
    Aug 10, 2018
    Posts:
    4
    Hi.

    I have a script that calls
    Code (CSharp):
    1. XRDevice.GetNativePtr
    and passes the pointer to a custom native plugin subsystem. That same script uses
    Code (CSharp):
    1. OnApplicationQuit
    to shutdown the subsystem.

    Unfortunately OnApplicationQuit is getting called after the GetNativePtr is invalidated. So it seems like Unity is shutting down the XRPlugin before OnApplicationQuit. The end result is a crash in my native plugin.

    Is there a way to detect that the XRPlugin is about to be shutdown? Looking at the reference I see an event for when it is loaded. But not an event that fires just before it is unloaded.

    I'm using Unity 2019.4 and this is all using the Oculus plugin.

    Thanks!
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    What do you mean by Native Plugin Subsystem? Do you mean a standard Unity plugin or do you mean a full on Subsystem implementation?

    Either way, your best bet is to manually manage the lifetime of the loader yourself. This way you are in control of when it starts and stops and you know the actual lifetime you are working with.

    See: End-user documentation | XR Plugin Management | 3.2.17 (unity3d.com)