Search Unity

Loading Multiple Scenes from same .unity file

Discussion in 'Scripting' started by ratuspro, Apr 13, 2022.

  1. ratuspro

    ratuspro

    Joined:
    Apr 5, 2015
    Posts:
    17
    Hello,

    I've recently faced a problem while trying to asynchronously load multiple scenes from the same file (using Additive Mode). The problem is not related with the actual process of loading scenes but rather with the addressing the multiple scenes loaded individually.

    In my use case, I want to load N World scenes at the same time from a Host scene. Each level then randomly generates itself. However, I would like to individually address each of the loaded scenes from the host scene.

    Using GetSceneByName or GetSceneByBuildIndex does not allow me to uniquely identify each scene since it always returns the first scene with a matching name or build index, respectively.
    I tried using GetSceneAt and play with the indexes based on sceneCount but when a new scene is loaded or unloaded their order changes, thus making it harder to track each scene throughout the game. Also, when loading, the only "reference" I get to a scene is to the loading process - AsyncOperation - rather than to the actual scene.

    Overall, it seems quite odd that the engine does not hold a memory reference to each scene. Perhaps it does, but does not make it publicly accessible. However, in the hierarchy, we can clearly see that there still is a relationship between all the scenes created based on the "clusters" presented.

    Is there a way to individually hold a reference to each scene?

    Thanks in advance!