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.

Resolved XR Plugin Unload

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

  1. ForrestSmithFRL


    Aug 10, 2018

    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.

  2. joejo


    Unity Technologies

    May 26, 2016
    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 (