Understanding How Levels Work In UE5
Note: If you’re not interested in studying the theory behind level creation, the practical tutorial may be found under the heading “Creating Levels in UE5 in Action.”
I want to go over some fundamental ideas regarding level design before we get into the actual details of making levels in Unreal Engine 5. We won’t get too deep into subjects like level design; instead, we’ll focus on the primary distinction between main/persistent levels and sub-levels.
Main levels are the levels, where the whole world in your game changes. For example; this section in Call Of Duty Modern Warfare 2 (2011) that takes place in Brazil was named as “The Hornet’s Nest”.
And this level was named as “Cliffhanger”.
Even though these two levels might be recycling some assets, their design and scales are completely different, in addition to small gameplay differences that call for distinctness in design. But these two major (overall design and the scale) elements are what differentiates a main/persistent element from a sub-level.
Let’s talk about sub-levels. Let’s think of that “Cliffhanger” level, where stealth is kind of a star of the act in Modern Warfare 2. In this first part of the game, we see that the playable character has poor visibility, therefore we do not need to load every single area and asset in that level immediately, which would give us to optimize our levels better. Another reason why we might like to have sub-levels in this main level is that, rendering fog is heavy on hardware. There are things that can be done to optimize it, but if you can optimize anything even just a little bit further, it is worth it. If this explanation doesn’t make everything clear, don’t worry. I’ll make an another post where I’ll be demonstrating how level streaming can be used in favor of optimization.
In other words, by making sub-levels, we can basically figure out where our character is and, based on that location, we can load or unload the resources in our game environment. We can see persistent/main levels as these are the levels in which all of our sub-levels could be loaded into. A persistent level doesn’t necessarily need to have a sub-level, but it might. In UE5 “Persistent level” will be always the active level, even if we unload all of our sub-levels.
Note: Depending on the genre and how the level is designed, a game can have only one giant persistent map and many many other sub levels. The concept I’ve explained here applies more to linear games rather than open world games and it just represents a general idea. It is not very rare to find persistent levels with no sub-levels.
How to create levels in Unreal Engine 5?
What I am about to advise is my personal preference. Using this method was very helpful for me to keep everything in my “Content Browser” organized.
- To create persistent / main levels, we can follow the File > New Level path.
- To create a sub level, we can go to Window > Levels > Levels (Yes, twice.) > Create New (or we can choose an existing map)
Creating Levels in UE5 in Action
To get started with the levels, well, we need multiple levels that we can load/unload or in other terms stream/pause them.
To add a new level to our game, we can click on File > New level and select a desired level from that menu. To save a level, we can press Ctrl + S. Although you can save your level in any folder, it’s a common principle to create one called Levels/Maps to keep things organized.
How to open levels in content browser in UE5?
To execute such task, all we need to do is navigating to the folder where our levels are saved in. In my case, it would be All > Content > FirstPerson > Maps.
If we double click on any of these levels, Unreal will load that level for us.
Creating triggers to change the current level during gameplay
Of course people who will be playing our game won’t have access to the “Content Browser” menu, so we need to create an event listener that triggers, when our playable character collides with something or someone, then we can unload the previous level and load the new level.
How do we create triggers then?
To keep everything organized, I’ll navigate back to my “Blueprints” folder and create an actor here. If you’re not familiar what actors are, you can read this post here. To create the actor, we can right click on an empty space and then > “Blueprints Class” > “Actor”.
Now all I need to is to double click on this actor, and attach a collision object to it so I can check if my character is colliding with it. This next step is not necessary, but I’ll be attaching a static mesh (Plane, in this case.) so my character can walk on it, but as I said, it is not necessary.
Now the next step is creating the trigger itself. Compile the asset first, then scroll down on the right side of the screen until you see the event listener called “On Component Begin Overlap“. (Make sure your collision element is selected. Otherwise you won’t be able to see the following menu.)
Clicking the plus (+) icon there will lead us to the “Event Graph” editor.
Compile, save it and do not forget to place your actor in your map and go test it! We do not need to create the plane to have the collusion by the way. Do not forget to go to File > Save all to save the changes you’ve made!
If you prefer “Open Level (by Object Reference)” all you need to is bringing that executable to the event graph and selecting the level you want your character to go to. And that’s it.
Some Extra Notes (Optional Read)
Window > Levels path reveals the sub levels in our level.
A very important note about default UE5 templates: As you might already swa in the tutorial, I am using the default FPS template that comes with UE5. And this template does not come with any “registered” levels. What it means is, if you try to display the sub-levels in this default template by going to “Window > Levels“, you’ll encounter the error of “This feature is disabled when world partition is enabled.” whether this option is enabled or not in the first place. This is the engine’s default behaviour. To avoid this issue and problems that it could create in the future, I suggest always starting with a clean level by creating a new level by using the method of “File > New Level“.