Give Page Feedback | API

Chunk Streamers - Scene Chunk Streamer

This Chunk Streamer can be used to load and unload non Addressable Scene Assets which have been added to the Build Settings window.

It is capable of double frame loading via the use of the SceneManager.LoadScene method, however under normal runtime operation it uses SceneManager.LoadSceneAsync for slower (as the loading is spread across multiple frames) but more performant loading. When World Cells are no longer needed, their Asset Chunks are unloaded in one of two ways:

1) If a Chunk Destroyer is assigned to the Streamer, it is used to destroy all Asset Chunks belong to the World Cells.

2) If no Chunk Destroyer is assigned, each Asset Chunk is destroyed and then the streamer yields for a frame.

If the Keep Scenes Intact option is enabled, the Streamer invokes a separate SceneManager.UnloadSceneAsync call for each scene associated with each destroyed Asset Chunk (since the scenes are now empty, this cost very little).

It's important to note that although SceneManager.LoadSceneAsync is an asynchronous method intended to avoid single frame bottlenecks, the integration of the scenes game objects into the main frame always occur in a single frame. This is a Unity limitation that cannot be avoided.

For Terrain and other single asset Chunks, this issue can be mitigated by using smaller individual Terrains (with smaller resolutions) or meshes. For non-Terrain and multi game objects Asset Chunks, Multi-Chunking can be used to break up the assets associated with a single World Cell into multiple Asset Chunks.

Creating A Scene Chunk Streamer Component

You can add this component by selecting a game object and then selecting from the Top Menu Bar:

Component -> Deep Space Labs -> -> SAM -> Chunk Streamers -> Scene Chunk Streamer

Adding A Scene Chunk Streamer Component From The Top Menu Bar GIF

or by selecting a game object and using the Add Component menu via its inspector:

Component -> Deep Space Labs -> -> SAM -> Chunk Streamers -> Scene Chunk Streamer

Adding A Scene Chunk Streamer Component From Add Component Menu GIF

Proper Scene Format And Error Handling

In order for the Streamable Assets Manager to make use of Scene Assets, it's necessary for the Scenes to be in a specific format. This format consist of the following two criteria:

1) The Scene must contain exactly 1 root game object. This game object can have as many children, grandchildren, etc., as you want, but it must be the only root game object in the scene.

2) The root game object must be in a game object state (activated or deactivated) that matches the Root State setting for the LOD Group using the scene (found on the Streamable Grid/LOD Group/Primary Settings tab). Generally speaking, it is recommended to us a Deactivated state for the scene root objects, which ensures the objects are not seen by the player before the Asset Chunk is able to be positioned correctly (see the Root State sub-section from the LOD Group Settings Sectino of the Streamable Grids Chapter for more info).

The Invalid Scene Format Message Level setting controls how the Streamer should respond to Scene Assets that are not formatted in the manner described above. The options include displaying a warning in the Console Log (which the user will not see), an Error (which the user will likely see), or not displaying a message.

Keep Scenes Intact

Normally, the Scene Chunk Streamer will load each Asset Chunk scene, then move the Asset Chunk (which is the root object in the scene) to the main scene. After, the scene (which is now empty) will be unloaded.

In some rare instances this behavior may present issues, for instance if you have some data associated with the scenes and don't want them to be unloaded.

If Keep Scenes Intact is enabled, the Asset Chunks are not moved out of the scenes and the scenes will remain loaded until the Asset Chunks are no longer needed and destroyed, however do note that the use of a Hierarchy Organizer may pull the chunks out of their original scenes.

Because keeping the scenes around is usually enough to avoid issues, moving the asset chunks out of the scenes is usually not a problem, however you should test this to be sure and avoid using a Hierarchy Organizer if you notice any issues.

Sorting Scenes

In order to load the Build Settings Scenes more efficiently at runtime, the first Scene Chunk Streamer in your game that runs will perform a sort of the scenes, to place them in alphabetical order.

How this sort is carried out is determined by the sorting related settings. These settings are global across all Scene Chunk Streamers and thus can be found under the Global Scene Chunk Streamer Settings section in the inspector of any Scene Chunk Streamer in your project.

There are several Sorting Methods available. You can find more information about each method by hovering over the Sorting Method label in the inspector.

Normally, the sort will be performed the first time a Scene Chunk Streamer is run in its Awake method. If this presents an issue for some reason, you can enable the Sort Scenes On First Load option, and the sort will instead be performed the first time a scene asset chunk would be loaded, for any Scene Chunk Streamer. Note, however, that this can cause a hitch in gameplay, if the number of scenes in Build Settings is large (test to find out, the sort algorithms are well optimized so this will probably not be an issue for most users).

If you are unsure which sorting method should be used, you can enable the Time Sort Speed method in order to see the time the sort method took (via the console).