-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AR Camera FPS drop after return back to the screen with UnityView #108
Comments
Had exactly the same problem (and the black screen problem). I solved this by fully reloading the scene and reinitializing AR Foundation after reattaching Here are few things that I found (not sure if they still apply):
|
Thank you very much for your instructions. As you pointed out, I'll try implementing an handshake mechanism when I return back to work. |
Hey @Luluno01, how do you deinitialize AR Foundation before detaching UnityView? I try running |
Something like this: https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api/UnityEngine.XR.ARFoundation.LoaderUtility.Deinitialize.html Found the precise code I use:
|
Thank you very much for sharing the precise code. |
I ended up by reloading the whole scene + restarting the AR session + passing the data back - in the user leaves the screen and comes back. So it works as:
I send a message from Unity to React Native after the Awake function runs: "awakeCompleted". I capture it in the React Native side:
My ReloadAll function in Unity: Finally, when the reload message is received from React Native, I pass back the existing data from React Native to the Unity scene:
|
Yes, that's exactly what I suggest. And if you find UnityView still shows all black and is not ticking after being reattached on Android, you may try Here is a short summary of the flow of remounting UnityView with AR Foundation running for those who might have the same problem: Unloading:
Reloading:
You may also implement alternative handshake mechanisms depending on what you need. |
Hi, I'm facing the same issue with Android, followed the steps above but I'm getting occasional crashes/inconsistent results when mounting back my Unity. |
No. Unity is not designed to restart without killing the process. I wanted to do exactly what you want to do for pretty much the same reason as yours, but it turns out you simply can't (unless Unity is to implement the support). In the end I found the embedded Unity crashes randomly because of a double-free bug. By solving that bug it no longer crashes. So if you can find and the cause to the crashes, find and eliminate it (it will crash the game even when running standalone). If it is out of your control, consider restart the entire app instead of the Unity part. If restarting the entire aop is unacceptable, try run |
They way that I solved this was to add private void OnApplicationPause(bool pause)
{
if (pause)
{
try
{
arSession.Reset();
LoaderUtility.Deinitialize();
LoaderUtility.Initialize();
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
catch(Exception e)
{
_messageHandler.SendConsoleLogToRN($"UNITY: OnApplicationPause {e}");
}
}
} in a mono behaviour |
This is only happening in Android - iOS is fine.
I open the StreetScreen having the UnityView component. Running okay. Go back home, then navigate to StreetScreen again. AR Camera FPS is significantly reducing.
(I use androidKeepPlayerMounted={true}, otherwise the UnityView comes blank after refocusing on the screen.)
Does anyone have any idea about how to find a solution to this? (screen video attached - FPS drop starts at 24th second)
ar-camera-fps-drop-after-refocus.mp4
The text was updated successfully, but these errors were encountered: