Jump to content

Level streaming for smooth transition


photo

Recommended Posts

Hi Cesio137,

The best option for switching portions of the world (maps in UE) without changing the world is to wrap each such portion into a Node Layer, save it to a *.node asset, and then load these assets on demand using the AsyncQueue class.

You can put a World Trigger in your Elevator zone to execute layer switching code.

You load your first level somewhere in Init() or Update()

    Node current_scene_layer = null;
	
    private void Init()
    {
      
        // putting the first layer to loading queue at startup
        int id1 = AsyncQueue.LoadNode("layer1.node");
 
        while(current_scene_layer == null) {
            // trying to take the loaded layer from the queue and setting it as current
            current_scene_layer = AsyncQueue.TakeNode(id1);
            // waiting... some LOADING... message maybe
        }
 
        current_scene_layer.Enabled = true;
 
        // add a callback for the trigger to catch a player enter event to switch a node layer 
        trigger.AddEnterCallback(enter_callback);
    }
    //...

Then implement the enter_callback function for your trigger somewhat like this:

    // callback for a trigger (where the player enters)
    void enter_callback(Node n)
    {
        // putting the second layer to loading queue
        int id1 = AsyncQueue.LoadNode("layer2.node");
 
        Node new_layer = null;    

        // check if the node is loaded into the queue
        do {
            // trying to take the loaded layer from the queue
            new_layer = AsyncQueue.TakeNode(id2);
            // waiting... some LOADING... message maybe
        } while(!new_layer);
 
        // switch layers, removing the old one
        current_scene_layer.Enabled = false;
        new_layer.Enabled = true;
        current_scene_layer.DeleteLater();
        current_scene_layer = new_layer;
    }   

This should do the trick. You can add your own layer management code depending on your world's structure, but the idea is like this.

Thank you! Hope this helps!

  • Like 2
Link to comment
  • 1 year later...

How can we manage those Node Layers in editor? I can't see any option to load/unload layers. They can be only enabled and disabled. What if I want to edit some huge continuous world and I want to place layers and create parts of this world inside those layers. It would not even fit into memory. Are the contents of layers loaded/unloaded automatically inside editor after they are enabled/disabled?

Link to comment

Meshes / Textures streaming is performing automatically. If you have correctly set up visibility distances for objects you should not have any memory issues. However, if you work with a really big worlds with huge numbers of objects you shouldn't expect that it would work smoothly on a PC with 4-8GB of RAM.

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Ok, but how can I control it more?

1. Is it enough to disable layer node in editor in order to unload its contents? Is this a way to create sublevels in editor? In Unity we have multi level editing - load/unload level from hierarchy window.

2. From the other side, in game, start with layer nodes disabled and enable them on demand? Is this the proper way to load next parts of the world? Are "world trigger" and "switcher" nodes the right way to do it? Distance based loading is not always the desired way. From the code above, I can see, that layers can be loaded on demand, but what is the purpose of doing that if everything is automated?

3. Is everything being loaded/unloaded asynchronously?

My case scenario is to progress through the levels linearly. Similar case as the mentioned elevator above. I don't want the engine to check all the objects all the time. I want to tell, when to load next part in game, but be able to create such linear world in editor.

So in short - what is the proper way of creating such linear world in editor and loading parts on demand in game?

Thanks
 

Link to comment

There is no much control over this behavior at this moment.

Quote

So in short - what is the proper way of creating such linear world in editor and loading parts on demand in game?

Do you have any issues with streaming already? I would recommend to simply create your world as-is and tweak it later by adding occluders / switchers and see how it goes. If you will have an issue with this approach you can switch to manual lopading control via AsyncQueue class.

 

Quote

1. Is it enough to disable layer node in editor in order to unload its contents? Is this a way to create sublevels in editor? In Unity we have multi level editing - load/unload level from hierarchy window.
 

3. Is everything being loaded/unloaded asynchronously?

Enabling / disabling nodes in runtime may result in some spikes since you can manipulate objects and add them into the scene only in main thread (even with switchers). Textures and meshes are loaded into the memory in a separate background threads, but added into the scene in the main thread only.

 

Quote

From the other side, in game, start with layer nodes disabled and enable them on demand? Are "world trigger" and "switcher" nodes the right way to do it?

Probably you will get spike in this case. Switcher is good when you don't need to see large portion of the world and you will never get back to it, you can simply disable it with switcher.

 

Quote

Is this the proper way to load next parts of the world? From the code above, I can see, that layers can be loaded on demand, but what is the purpose of doing that if everything is automated?

If you need very precise control on what is being loaded and when you can use AsyncQueue and do all the trickery manually.

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Thanks for the answers. I am asking all these questions, because I faced such problems in Unity - huge spikes and hiccups. I want to know the possibilities here, before I even start to think about migrating my project. In Unity I solved this problem with custom approach - baking scenes to custom format and spawning and activating objects in time slices - all in main thread without any spikes or hiccups.

Link to comment
×
×
  • Create New...