I’m currently working on an endless runner game, and I’ve managed to use Level streaming instead of placing actors on the scene.
Let’s assume I have 40+ Sub levels within one Persistent Level, but they are all hidden, and the game loads only two or three of these levels at a time, and as the player overlaps a trigger box, it loads two more, and unloads the previous ones.
The question is: is this okay performance wise? I mean this many sub-levels within one persistent level won’t cause performance issues?
If a level is unloaded, it won’t affect the game’s performance at all right? that means I can have an infinite amount of sublevels within the editor. but managing this high amount of levels won’t cause the engine to crash or generate performance issues at runtime/or in the editor?
Sorry for my bad grammar, and I hope you can understand the question and it makes a little sense to you.
I’m doing something similar with unloading levels and loading in new ones. Apparently unloading doesn’t actually delete them properly. When I keep loading in levels and unloading other ones, I do see my fps start to drop. I haven’t found a solution to this yet though.
In c++ you can use bIsRequestingUnloadAndRemoval flag in ULevelStreaming. Set it to ‘true’ and engine will remove that level streaming object once sub-level is unloaded.
I’m wondering how to access this in c++ or expose it to blueprint somehow.
It is actually interesting. Unfortunately I’m doing my project entirely in Blueprint so yes, exposing it to blueprints could be the only option, if only there is a way for it…
I found bIsRequestingUnloadAndRemoval in my levelstreaming.h and put the ‘UPROPERTY’ tag above it. Seems it’s not that simple to get it to show in blueprint.
Here’s a step by step instruction I gave [USER=“1115524”]Jack W Lewis[/USER] in the UE4 Subreddit recently.
Maybe someone here finds it useful, too.
In the Editor go to File->New C++ Class
Select “Blueprint Function Library”
Choose a name (leave the directory as is), in this example we’ll keep “MyBlueprintFunctionLibrary”
Unreal will create and compile the new files for you
In your file explorer go to the previously selected folder (default: “<yourproject path>/Source/<ProjectName>”)
and open the two files with the name you have chosen in step 3, ending with .cpp and .h respectively
“DestroyStreamingLevelInstance” will now be available as a node you can place in your blueprints.
Note: Set “Self” (or any valid Actor) as “Sender” and as “LevelName” enter the name of the level instance you want cleared.
This node unloads a streaming level instance but also removes that instance completely.
There is a bit of overhead, but it isn’t significant in most cases where you add sublevels in the editor.
I have answered a similar question recently and posted some test numbers.
Though when you start approaching “an infinite amount of sublevels”, as in the case of an Endless Runner, you risk running into a problem where the size of the internal array that stores all those instances (active and inactive) could cause the performance issue you are experiencing.
The code exposed to BP above would remedy that issue, as the instance will be removed from that array.