google-ar / arcore-unity-sdk

ARCore SDK for Unity
https://developers.google.com/ar
Other
1.4k stars 402 forks source link

Camera background freezes when loading a second scene that uses ARCoreSession #718

Open alexpalko opened 4 years ago

alexpalko commented 4 years ago

SPECIFIC ISSUE ENCOUNTERED

I am using plane detection in a scene using ARCore. When first loading a scene which contains an ARCoreSession component, everything works smoothly. On a second load on a scene which uses ARCoreSession, the camera freezes on the last frame recorded in last scene in which the ARBackground worked properly (with Instant Preview) or it just shows a black screen (on a mobile device). Plane detection seems to be working properly and only the camera background is frozen. Only a single instance of ARCoreSession and camera with ARBackground exist and are enabled at a single time.

VERSIONS USED

STEPS TO REPRODUCE THE ISSUE

I have created multiple examples of this issue occuring, plus one possible workaround. They're uploaded at this repository. The examples are based on the HelloAR scene from the Google ARCore sdk for unity: https://github.com/alexpalko/Unity-Google-ARCore-Camera-Freeze-on-Scene-Reload

WORKAROUNDS (IF ANY)

The third example in the repository above shows that using a single instance of ARCore session and camera that will run continuously throughout the application will solve the issue. However this means that plane detection will run continuously throughout the entire application, which is not a behavior I desire. If I try to pause (disable) the camera or the ARSession, the camera freezing issue happens one again.

ADDITIONAL COMMENTS

I have done some research and the only issue somewhat related to mine can be found on this thread: https://github.com/google-ar/arcore-unity-sdk/issues/181#issuecomment-398322188 However, in Example 6 I have created a single scene, and tried to reset the instance of ARCoreSession (destroying and then instantiating a new session). This did not work, and the camera freezing issue happened in this case too.