Search Unity

Question Proper way to load a Scene in VR

Discussion in 'VR' started by FlightOfOne, Aug 12, 2021.

  1. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Hi,

    When I load scenes in VR are it keeps locking up jumping into the compositor and back. I believe there is a way to control this using the steam VR plugin but I am using the OpenXR with XR management.

    I want the players to smoothly transition from one scene to another without the stutter, making it seem like the application is about to crash.

    How do I go about doing this properly? Thanks!!
     
  2. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Are you loading your scenes asynchronously? I suspect what you are seeing is the main thread stalling?
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I find that even with asynchronous loading, there are often dropped frames and noticeable stutter.

    What most games do (including mine) is just throw up a big black screen with a "Loading..." image of some sort. Then at least the player knows to be patient.
     
  4. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Yes, I am using Async. The player is moved to a holding area while loading, still madly stutters.
     
  5. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    I have a little holding area/cage with a progress bar and says loading. But this is in world space, players can look around etc.. Do you think it would make it better if I plaster a UI right into the camera saying loading, and have a stationary camera instead of a tracked one?
     
  6. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    This is what I mean (see this video) but I want to do the same without using SteamVR. Is there a way to access the background of the headset with Unity?

     
  7. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Sorry, didnt have time to watch that whole video, what do you mean by accessing the background?
     
  8. NevinAF

    NevinAF

    Joined:
    May 12, 2021
    Posts:
    36
    The big issue is that load async does the best it can but oftentimes has to drop frame rates to load in objects. SteamVR has the advantage of being able to load their default environment in the background in a different thread than what is used in Unity (this won't be the case if you are building for other platforms).

    That being said, there are ways to optimize the loading times. I think the first step is to determine when the problem occurs:
    Code (CSharp):
    1. asyncOperation = SceneManager.LoadSceneAsync("Scene3");
    2. Debug.Log("Pro :" + asyncOperation.progress);
    3. //When the load is still in progress, output the progress and the time that passed between frames
    4. while (!asyncOperation.isDone)
    5. {
    6.      yield return null;
    7.      //Output the current progress
    8.     Debug.Log("Loading progress: " + (asyncOperation.progress * 100) + "%    Time passed since last frame: " + Time.deltaTime);
    9. }
    If there is a problem between progress 0% and 89%, there is most likely an issue with memory allocation and resource loading. This would be due to large particle systems (check capacities) or simply a ton of game objects (things like large animations, audio, and meshes, tho normally async loads in a lot of objects fairly smoothly).
    If there is a problem between progress 90% and 100%, the issue is Awake() and OnEnable() functions. You most likely have too many objects 'initializing' at once. Consider using a script to slowly activate the game objects in a sensible order.

    To recap, SteamVR doesn't suffer these issues because it can render frames independently from the Unity pipeline. The above are some good starting points to prevent async loads from getting bottlenecked at one point.

    Visually, you should be fine running/rendering the holding area/cage as long as the load doesn't stall the render times (I do the same thing). Reach out if you need any more direction or suggestions.
     
    Last edited: Aug 13, 2021
  9. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Hey, Thank you! This helps. Yeah, it is somewhere between 0-90. It is not horrible (but I have a decent PC and players may not) but it kicks in and out of the headset.

    In a normal game, this wouldn't be an issue because it is not going through to another system, so you never notice this problem.

    With VR the best and the proper way would be to get hold of the headset's API (what you kick in and out from) and activate (instead of the holding cage) that and wait until loads and then bring the view back to the game. You can do that with the SteamVR plugin and I think you can do this with Oculus too. We need a way to access this and do a similar thing with OpenXR.
     
    Last edited: Aug 14, 2021
    NevinAF likes this.
  10. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    If you were to grab your headset and put it on without a game running, the background you see. Steam VR compositor background or whatever Oculus and WMR call theirs. Guess an API.
     
  11. NevinAF

    NevinAF

    Joined:
    May 12, 2021
    Posts:
    36
    I definitely agree that is a good way to load in VR without worrying about optimizing scenes for loads, but it will come with some limitations when it comes to the loading scene (ex animations, physics, sounds..). Though trying to go overboard with transitions may be too much especially in VR. If you find some of the API calls let me know, I'd be very interested!
     
    FlightOfOne likes this.