Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
2.99k stars 1.11k forks source link

[Bug] unity Application.Unload() doesn't work correctly on AR mode #987

Closed moheydy closed 2 years ago

moheydy commented 2 years ago

I build a Ar application, Everything is good but when I use Applications.Unload() ( I want in future embedded my app in a android studio Applications ) and back again in App , Ar camera have a lag and leak for about 10 second and many times for always until Quite of App (even in empty Ar app i have this issue)

DavidMohrhardt commented 2 years ago

Can you provide a recording of the behavior?

DavidMohrhardt commented 2 years ago

A possible workaround would be to deinitialize your active loader (see the StopXR method in the code-block) during the Application.unloading callback manually.

moheydy commented 2 years ago

Tanks I fixed this by manually calling StartXR function in Awake and StopXR before Unload

private void Awake()
{
    Application.unloading += OnUnload;

    FindObjectOfType<ManualXRControl>().StartXR();

}

static void OnUnload()
{
    Debug.Log("Unloading the Player");
  FindObjectOfType<ManualXRControl>().StopXR();
}

Just don't forget to remove tick Initialize XR on startup in PlayerSetting (This function doesn't work correctly after first unload even if you call StopXR() )