Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

What's a good practice for interactive scene loading?

Discussion in 'World Building' started by pekdemir, Nov 6, 2018.

  1. pekdemir

    pekdemir

    Joined:
    Nov 7, 2016
    Posts:
    4
    Hi there,
    I'm working on a VR-Game and I'm trying to build a setup where I can interactively load (and unload) relevant scenes as the player advances to new areas to keep memory usage low.

    My plan was to create a grid of scenes (so each scene can be edited separately) and make the game logic load and assemble the needed scenes before the player reaches that area (and also eventually does some sort of stupid manual garbage collection when scenes are far enough from the player).

    However - I did all that already and it basically works fine. The Problem is, that there's some really annoying camera stutter while the new Scenes are being loaded (I'm loading them using SceneManager.LoadSceneAsync btw.). The profiler shows a drop below 40fps when the scene loading kicks in.

    So my noob questions here would be:

    - Is this even a good approach?
    - Are there obviously better best practices?
    - Is there probably a way to offload scene loading to a separate thread to avoid the stuttering?

    Any help & comments would be very much appreciated. :)

    Regards,
    Onur Pekdemir
     
    LinnPeder likes this.
  2. The approach is good, but on VR, it's a really hard problem to solve. You may have to have very small pieces of scenes around you. Not to mention that you need at least nine subscenes around the player to be active at any given time.

    If you want to study other people's work you can check out this asset: https://assetstore.unity.com/packages/tools/utilities/scene-streamer-38168
    Pixel Crushers is a very well known and reputable asset publisher, I'm pretty sure he has a readable code to study.
    Or you can use it if you want.

    There are two more reputable Scene streamer assets on the store:
    - Sectr Stream - the game called Firewatch was made with this asset and it basically uses colliders to load/unload given sectors from the scene (hence the name)
    -World Streamer: it's more complicated asset with a lot of tools and multilayered scene streaming (objects included), it requires more study and it may not be suitable for VR, I have no idea (about VR in general, just some common sense you know)
     
    LinnPeder and pekdemir like this.
  3. pekdemir

    pekdemir

    Joined:
    Nov 7, 2016
    Posts:
    4
    @LurkingNinjaDev : Thanks a ton for your reply! :) I will check the tools you've mentioned.

    From what I could gather so far (by reading forums and discussions) it seems like LoadSceneAsync seems to cause the stuttering (e.g. this thread on reddit is discussing this problem: https://www.reddit.com/r/Unity3D/comments/76nt7o/how_do_i_make_a_loading_screen_that_doesnt_stutter/ ).

    It would be nice to know if the new Job-System will somehow be able to help with this issue. Right now I'm tending to try to switch my current "async scene loading logic" to an "async asset bundle loading" system. Don't know at all if that will get rid of those nasty hiccups though. So I should probably do some more investigation first ...

    I was stupid enough to assume that LoadSceneAsync would be nicely thrown on an own thread by the Unity Core System. But as much as I could understand, that doesn't seem to be what's happening internally right now. Sooo ... seems like I've wasted many hours on this approach. *sigh*

    Cheers & Thanks again! :)
     
  4. Never ever assume such a thing. Multi-threading in Unity is a fairly complex question and a lot of restriction are true both to the engine and to us as well.

    BTW, the example in the documentation clearly shows that it's an IEnumerator so it cannot be on a separate thread.
    https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html