Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Multiple AR Foundation scenes performing poorly

Discussion in 'Handheld AR' started by dyuldashev, Oct 19, 2018.

  1. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    61
    I have a menu scene (non-AR, three buttons only), and three AR scenes (AR Foundation). The first time I run one of the scenes, it's all good. I go back to the main menu. I pick another scene, and now, the tracking is not so stable. Worst of all, it crashes when I try to go back to the main menu. Here's a crash log from XCode (from AR scene back to menu scene second time), and you can see that the UnloadGameScene() function is trying to access that has already been deleted:

    UnloadGameSceneError.png


    AR Scene 1: Smaller environment, Light estimation enabled, only realtime lighting
    AR Scene 2: Smaller environment, Light estimation enabled, only realtime lighting
    AR Scene 3: Larger environment, Light estimation disabled, baked lighting

    In my opinion, here's what's happening. When it tries to exit from an AR scene, it has to unload some AR assets. It's unable to do so. Why I think that way is simple: for the first time, it all works great. The second time, on the other hand, we start having some issues. It just means that there is something going wrong right when we switch the AR functionality off and then on again.

    I wonder how the AR functionality persists in between scenes, how it is reset, how it's unloaded, and how it's loaded. Really hope to get some insightful tips to resolve this issue and to get a better understanding. Thanks... @jimmya @tdmowrer
     
    Last edited: Oct 19, 2018
  2. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    61
    Run in this order:
    -Menu ---> AR Scene 1(stay there for a minute or two)
    -Go back to the main menu
    -Menu ---> AR Scene 2(stay there for a bit as well)
    -Now, try to go back to the main menu again ---- This is where it's crashing for me

    Also, note how I have different light settings in those scenes. I honestly don't know the root of this issue, so I am looking for an insightful solution...
     
    Last edited: Oct 19, 2018
  3. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    Hey
    Out of interest.. try your setup with just basic cubes and a simple shader without shadows...

    Im having a performance drop returning to the same AR Scene and reloading the same geometry... And when I profile it my Camera.Reder is taking more time.. for the same scene... It appears to be in the Render Opaque Geometry. I'm looking to see if its mesh complexity, lighting or shaders!
     
  4. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    Ok, after a quick test... turning off cast and receive shadows for my meshes has greatly improved things. I need to do further tests but in case you want to try it to see if it helps. I havent come to any conclusion as to why it would run at 60fps no prob the first time but not on reload! But it does seemed to have helped.. on initial testing.

    Its also reduced my draw calls massively too obviously!
     
  5. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    61
    By the way, how are you testing this? On iOS or Android?
     
  6. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    @dyuldashev Currently on Android... I'll do an IOS build tomorrow and let ya know. But in the meantime, let me know if it makes any difference on your end. I'm also interested to hear if your tracking stall for about 5secs after you disable the ARPlaneManager on IOS
     
  7. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    61
    This is an official bug. Here are the steps to reproduce it.

    Info: Unity 2018.2.11f1----XCode 10---iOS 12---iPad 2017

    Setup:
    1) Download the sample AR Foundation project from Github.
    2) Duplicate the sample scene(two simple AR scenes that just place cubes on planes)
    3) Create a non-AR menu scene that goes to these two AR scenes


    Bug:
    1) We go to one of the AR scenes
    2) Go back to the menu scene
    3) Now, go to the other AR Scene
    4) When you try to back to the menu scene again, it crashes

    Here's a sample project link for your convenience:
    https://drive.google.com/file/d/173xgKOjcqsVQzuXHY8JyJVmqzjxzn2dX/view?usp=sharing
     
    Last edited: Oct 20, 2018
  8. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    61
  9. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    792
  10. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    61
    What do you mean by resetting the ARSession GameObject? I am going from an AR Scene to a non-AR Scene, by simply calling SceneManager.LoadScene(non-AR Scene);
    Where am I supposed to recreate the ARSession GameObject? Before calling the LoadScene() function? I didn't quite get the logic behind it because I am not trying to Reset() an AR Session, I am trying to exit from it(no recreation should be necessary while exiting).

    I just want to have 2-3 AR scenes, and I'd like to know where to destroy and where to recreate it. Does it mean that ARSessions are not destoyed when we go to a different scene?
    Crash:
    1) non-AR -----> AR scene 1 ---->back to non-AR(menu) ---works fine
    2) non-AR -----> AR scene 2 ---->back to non-AR(menu) --- crashes
     
    Last edited: Oct 20, 2018
    GreeneMachine likes this.
  11. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    61
    As I stated multiple times, I am not talking about Android. Please, read carefully when you reply because I never indicated that I was having problems on Android. Thanks.
     
  12. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    Does back and forth to the same AR Scene 1 cause the crash too?
     
  13. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    61
    I checked, and yes it does happen with one AR scene as well. And it's the simplest AR Scene possible, the one from the AR Foundation Github sample project.
    1) Menu(non-AR) -----> AR Scene -----> Back to Menu
    2) Menu(non-AR) -----> AR Scene -----> Back to Menu -----Crash
    But that's not surprising, is it?

    And @jimmya stated:
    "the recommended way to do AR->non-AR or different scenes is to destroy and recreate the ARSession component or GameObject. See https://forum.unity.com/threads/multi-platform-handheld-ar.536313/#post-3540191"

    @tdmowrer this was your reply, would you please clarify it? Thanks.

    I don't even understand how this is applicable in this case. What do you think?
     
    Last edited: Oct 20, 2018
  14. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    Yeah, I was just double checking the relevance of the second ar scene ...

    I'm also interested in that response from jimmya... hope he clarifies what he means as I also would have expected the scene change back to non ar main menu via scenemanager to unload/destroy all ar objects in the ar scene on exiting.. so returning to it would/should be same as loading it for the first time.
     
    dyuldashev likes this.
  15. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
  16. rob_ice

    rob_ice

    Joined:
    Nov 11, 2016
    Posts:
    112
    How did you maintain a static baked object in an AR Scene? Have had trouble doing this before!
     
  17. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    792
    Ya sorry - I tried this out myself and it seems we have a regression in this interaction.
     
  18. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    792
    here is a workaround - use these versions of arfoundation and arkit xr plugin: Screen Shot 2018-10-23 at 12.14.15 PM.png
     
    JelmerV likes this.
  19. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    @jimmya What min target ios ver should we aim for with these package versions
    Thks
     
  20. virendra_bhoriwal

    virendra_bhoriwal

    Joined:
    Oct 25, 2018
    Posts:
    3
    Hi there, did you got the answer of your question as I am also going through the similar issue. My app also crashing. Please help if you have an answer. Thanks !
     
  21. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    490
    There seems to be several issues discussed in this thread, but the scene switching / multiple scene crash was resolved in last week's release. Please update to the latest packages and see if that resolves the issue.
     
    virendra_bhoriwal likes this.
  22. virendra_bhoriwal

    virendra_bhoriwal

    Joined:
    Oct 25, 2018
    Posts:
    3
    Thanks for the package updates ! Crash issue has been resolved now. Lots of thanks ! :)
    when will the image tracking features be released ?? As I currently need in my project.
     
    newguy123 likes this.
  23. unity_ldsv76wk53-POA

    unity_ldsv76wk53-POA

    Joined:
    Jun 8, 2019
    Posts:
    1
    I also have the same problem. I try to change an AR scene to a scene without 3D. When I return to the main scene (With 3D) the camera does not activate. What is the problem?