Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Best practices for loading world regions.

Discussion in 'World Building' started by X1r15, Dec 3, 2021.

  1. X1r15

    X1r15

    Joined:
    Dec 19, 2019
    Posts:
    12
    Hello Everyone,
    I am wondering what would be best practice to address this scenario:

    I am having a typical metroidvania scenario:
    1. Let's assume the world's size is significant
    2. The world consists of multiple regions
    3. Each region consists of several levels

    I would like to optimize it a little bit and I am having two ideas but I am not sure if they are actually the right ones:
    1. Treat each level as separate prefab, assemble the whole level together but deactivate the levels that are far away. When the player gets close to new levels activate them and deactivate the ones that are far away.
    2. Treat each level as separate prefab and create and instance of it when player gets close. Store the state of that level in a file. Once it is created load the state, once it's removed store its state.
     
  2. steven1022

    steven1022

    Joined:
    Sep 8, 2012
    Posts:
    21
    Activating and deactivating might be okay if you aren't worried about overall memory up front.

    If you run into memory issues based on the world size most would recommend you look into world streaming which takes scenes and loads and unloads them completely in the same way. This is similar to your nested prefab idea but was common before prefabs could handle it from what I read.

    Pixel Crushers has a nice example to show the concept of scene streaming (https://www.pixelcrushers.com/scene-loader/). There are some paid assets if you search world streaming on the asset store.