How To Load And Unload Sublevels For Optimisation - Unreal Engine 5 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys mizo frizo here and in this tutorial I'm going to be showing you how to load and unload Su levels within your level in Unreal Engine 5 so you can see I've got this platform here and a little hallway over here and if I run through to the other end there is a platform also at this end but what you don't see while I'm running through this hallway is that I have actually unloaded the platform from the other end so once again if I run through here you'll see the platform is indeed loaded at the other end if I press f8 to eject and have a look again the other one has unloaded so you can see this at work if I just grab everything from my little hallway here and drop it out of the way you'll see that I run over here this platform loads the other one has unloaded and if I run back visce versa so this is basically an altern alternative to World partition uh World partition you would probably use in an open world game but in something more closed in and linear this is a very efficient way of optimizing your game so that uh you're in control of what Su levels are loaded at any given time so without further Ado guys let me show you how to do this all righty guys now very very quickly before we get started um if this video is of any use or value to you whatsoever please hit like And subscribe and if you are so inclined please do consider making a small donation to the channel via the YouTube super thanks function it really does go a long way to keeping me going and continuing to bring you guys quality content all righty let's get started so all I've done is I've created a new project using the third person template but I do believe that uh the third person template has World partition enabled um by default um we cannot use World partition uh in like at the same time as uh suevel streaming so they're basically it's one or the other so what we're going to do is create a new map what I might do is just in content make a new folder and call it level and in that folder I'm going to create a new level just a basic level um I can save this right away in my level folder and I'm just going to call it new mapcore persistent it's going to be our persistent level and this is something uh that you want to consider very carefully when you're doing your Su levels is uh What actors you leave within your persistent level so this one will always be loaded no matter what we load in and unload whatever sublevels we load and unload this one will always be loaded so for example leaving your sun in uh in your persistent level your directional light is probably a good idea because you only really need one Sun so you can just leave that loaded in and then that will be loaded for any sub levels that you go into um something like a postprocess volume as well is something that you might want to carefully consider if you have a post uh postprocess volume with infinite bounds then uh that will affect every Su Lev um so you may want to do a postprocess volume for each Su level that you create um so we don't want actually any level to be basically loaded in um we don't want any persistent level uh I'm going to leave the the you know the lights and the height fog and Sky atmosphere Etc I'm going to leave all that in um but what I'm going to do is just uh create my first suel and how I'm going to do that is I first need uh levels window so I can go up here and click window and levels and you'll get this levels window I'm just going to grab this tab and I'm just going to dock it down here next to World settings so I've got my levels right here um what you can do is you can click this little drop down here and you can create a new sub level and and I'm just going to make it an empty level cuz I do not want it to have any lights or fog or sky or anything like that I've got all of that in my persistent level so I'm just going to create an empty level and I'm going to call it new mapcore suble one something like that uh you can use whatever naming conventions you know will help you keep track of of your project U so I'm going to call it new map sublevel one and now you can see it's been added over here in this levels tab here um what you can do is you can see it's sort of highlighted uh it's the selected level it's the current level you can just doubleclick any level and you will now be editing that level what you can also do is click this uh someone's level details and it'll bring this level details window up uh you can also just grab this and I like to just dock this over here next to the outliner and now whenever you select a level a suevel uh you'll get these level details right here so let's add something to Su one Let's uh just add something to stand on um so let's just add a cube and I'm just going to make this a bit bigger whoops camera speed and where's my player start oh my player start right here and Okay so we've got our first sub level here Su level one um but the problem is if I hit play I it's not going to load I'm just going to fall and uh die so the reason is that this is a suble it's not in my persistent level so it's not loaded by default but what we can do here in the level details is check initially loaded and initially visible and now if I hit play this little Su L is loaded initially okay um another uh way you can do this instead of uh creating a new is you can add existing so for example if I go add existing and then go into the third person Maps folder and add the third person map you can see I've now added the third person map in here um you can change its position up here in the level details so you can move this around wherever you like put it wherever you like um we're not actually going to use this level so I'm just going to delete it and how you can do that is you can just right click on third person map and remove selected and it will ask you to confirm remove that level okay so we're going to basically just have three Su levels here and our little uh a little Corridor is going to be in Su two and then we'll have suev three at the other end so what we can do is just create a new level so create new uh empty level and in My Level folder I'm going to click my Su LEL one so that I've got my naming convention here and I'm just going to change this to suble l two and now we've got sub Lev two here if I have Su LEL two selected so if I double click on that one just case and I duplicate this Cube it will now be in suble two and you can tell what Su an actor is in by this little window that pops up down here so you can see selected actor is in new map suble 2 and uh my current context is my suble two if I click this other one you'll see it's in Su one like so Su one Su two so let's create one more suev um let's see if I can just duplicate this no it's just going to duplicate the cube so I'm going to create another new suble LEL Another Empty level and I am going to call it suevel three and then I am going to duplicate this Cube once more and now we have one 2 and three but as I explained earlier um the Su Lev one we have checked initially loaded and initially visible so it is loaded but these other levels these other sub levels are not um what you want to check uh because we're going to obviously be loading these in uh during runtime so we're going to be using blueprints we want to right click on these sub levels and change streaming method and make sure it's on blueprint um so obviously persistent is the only one that's going to be always loaded um the other ones we want to make sure are on blueprint which it should be by default now there's a couple of ways you can go about this um I'm going to show you both the first way I'm actually just going to move this off to the side like this and you'll see why in a moment what I'm going to do is I'm going to go to my persistent level so double click persistent level and then I'm going to click add here and I'm going to look for a level streaming volume right here level streaming volume I'm going to drag this in and I'm going to resize this to basic basically Encompass this whole suev here and about half of my Corridor so I'm actually just going to make it extend um sort of past the end like so and about halfway across this second suble Lev here and I'm also going to make sure that this volume encompasses absolutely everything um so nice and high as well so we can't jump out of it you know if your if your suble Lev had more verticality you would want this to extend high enough so that you cannot Escape it um because what this volume does is it streams a level and when you exit the volume it unloads that level and how we want to add this to our suble streaming so obviously this one is going to stream this first suble what we want to do is Select that suble and then in the level details here you'll see streaming volumes I can add one here and drop this down and then I can select the level streaming volume that I've created there so now when I leave this uh this volume this level will unload and we can see that by selecting this second level I might just select the second level and check initially loaded and initially visible and then I'll hit play and if I go over here and I exit that volume it's going to unload that level and if I come back it's going to load it back in we actually want that to extend a little bit further about halfway across this platform like so nice uh and we can do that with our other suble so so I'm just going to hold alt and shift and duplicate this one and put it right over here and we don't actually want these to overlap too much um the main reason is because this is an exercise in optimization so you obviously do not want both of these levels to be loaded at the same time the whole idea is that you've just got one or the other loaded um so it's okay if they're touching or overlapping a little bit but if they're overlapping quite a lot uh Unreal Engine doesn't really know which one to have loaded so some of them can jump in and out is what I've noticed uh okay so just with those volumes that is all that is oh we actually need to add this one sorry we need to add this one to Su level three so select suble three add a streaming volume and select level streaming volume to uh if you're not sure which one it is in this dropdown you just want to uh go to your outliner and just check which one is which um you know you could rename these but I know that this one here is level streaming Volume 2 so for uh suel 3 I want to select level streaming volume 2 now that that is assigned I can come over here and this level will load and this one over here has unloaded like so nice there is uh one other way uh to do this there may be a couple of other ways but these are going to be the two main ways that you want to do this I'm actually going to delete these streaming volumes and I'm going to manually load and unload so basically I'm going to create a more precise uh volume that's going to load and and unload these sub levels so just in my content folder I'm going to create a blueprint of type actor and I'm going to call it um I'm going to call it BP uncore um streaming streaming volume something like that I'm going to open this up and the first thing I'm going to do is add a box collision and I'm going to call it load load in box call it whatever you like um I am going to make this a bit bigger maybe a bit narrower and and I'm going to move it up so that the scene rout is at the bottom there um and just for sort of ease of use while we're setting this up I am going to search for hidden and I'm going to uncheck hidden in game okay I am also going to duplicate that box and I'm going to call the other one load out box and I'm going to move this one back like so now it's a bit hard to judge the size of this at the moment until we put it in the level actually let's just drag one of these into the level to see how big it is and I also might just grab my third person character blueprint just to get an idea of the size here um this is also quite hard to select at the moment so another thing I'm going to do is add an arrow and I'm going to just put this about in the middle about there um make this nice and big and I am going to duplicate this arrow and the other one I'm going to turn around 180° and I'm going to change to Blue so that's our load out box and that's our load inbox um it's up to you how you want to set this up but um I'm actually just going to turn these arrows around 180° so that my my blue arrow is on the load in volume and my red arrow is on my load out volume let's have a look at this now it's still quite small so let's just grab these volumes and make them bit bigger like so and and that should be fine for a doorway um yeah that's nice and Tall there we go okay um and the next thing we want to do is create some Logic for these to load and unload suble levels so what we want to do on our load in box is we can select it and if we scroll down in the details panel you'll see these events here and on component begin overlap we can add one of these and this is where we're going to load something in but we don't want this to load a level just because any old actor um you know overlapped with this box we want to make sure it's our player so I'm going to grab off of other actor here and I'm going to find actor has tag and let's check if the actor has the tag player and put that on a branch and then this is where we're going to load in our level so let's just quickly add this tag to our player I'm going to contrl C that and I'm going to open up my third person character and search for tag and then here under actor Tags I'm going to add one tag and call it player like so nice so that's a nice little easy way to check that it's our player that's coming through um and on our load in on true we are just going to search for uh load load level by name load level instance by name that is not the one load sorry load stream level by name sorry about that load stream level by name and then in here you want to put the name of the level you want to load and you want to obviously make it visible um after load so instead of typing in the name here what we might do is just promote it to a variable um and we'll call this level to load something like that level to load and make it instance editable so that we can change this for every instance of this blueprint that we drop into our level let's also on the load out box we can right click and add event addon component begin overlap and we can copy this make sure you plug other actor into the target here and then here we are going to unload stream level by name can also promote this to a variable and call it level to unload and and make sure you make that instance editable as well like so nice so that is all set up and now when we place it in our level we can go to the details panel and we can change the level to load and the level to unload here um so what we might do is I just want to double check so our load in box is the one that's going to load is on the blue side so um when we when we touch this uh first one on the blue side it's going to load a level so I probably want to turn this around this way and I want to put this in a position where you know you can't you can't go around it um so I might just make these wider and we also want to double check the space between these volumes because you don't want to be able to touch one volume while you're still touching the other one or you might be able to you know it will load the other level and and then you'll come back and and it won't unload what it's supposed to unload if that makes any sense so I might just drag these away from each other ever so slightly oh these arrows are parented to these boxes that's okay um let's just make these quite a bit wider I know this is uh making my arrows pretty funky but it doesn't matter too much all righty so when we go through this blue volume what we want to do is uh load some level 3 so we can just check in our level folder here suble LEL 3 we can rename this and contrl C to copy the name and then here while we've got this blueprint selected over here level to load we can paste that in there and um level to unload is actually going to be the same because if we come back this way we want it to unload that level if that makes any sense um nice so now what I can do is I can just hold shift and ALT and copy this move it over here turn this around make sure it's in the right spot and now it wants to load and unload level one so just going to change this to sub level one now obviously um you know we we this could be the same variable if it's the same suev but this will have different uses you know um you could drop this anywhere and you can make it load and unload whatever levels you like um I'm just going to get rid of this this was just for a scale reference and now this should be working so we can see our boxes here and if I go through this one it's it's going to load that next level and when I come this way it's going to unload that old level and now I'm over in this level and vice versa nice so what I was talking about with the space between these volumes is you you don't want to be able to touch both volumes at the same time because the way this logic is set up is it's on begin overlap so you can see I touched this F volume here it loads I touch this one it unloads and if I was able to touch sort of both um you know it wouldn't unload I'd be able to load it and not unload it and that is sort of uh one of the benefits of those level streaming volumes that I showed you earlier um you know you can you can do a combination of both or you can do either um but now you basically you've got all you need to know to load and unload sub levels within your level ah one other thing I'd like to talk about is um which suev or which level these uh these uh blueprints are in so at the moment you can see they're in our persistent level cuz that's where we put them if I hit play you can see that both of those blueprints are there they're already there um but you can put these inside of suble levels so what I could do is I could select this one for example and I could go to my levels tab here and I could right click on Su one and I could move selected actors to level so if I do that this blueprint is now in suble one um and this one here what I could do is I could right click on suble 3 Move selected act as to level and that one is now in suble 3 so if I hit play you'll see that that other blueprint is actually not loaded you cannot see the Collision boxes and then it is loading in and if I run over here the other one loads out that uh those volumes have unloaded so this uh for example if you had a door um as part of this blueprint you could have a door that you're opening such as in Dark Souls a very slow door and it's actually um you know a bit of a cheaty way of loading the next level without the player realizing you would obviously um if that door was in a level it would need to be loaded for you to be able to see it if you know what I mean um nice all righty guys that's all we set out to do today so if this tutorial has been of any use or value to you whatsoever please hit like And subscribe and I will see you on the next one
Info
Channel: MizzoFrizzo
Views: 956
Rating: undefined out of 5
Keywords: blueprints, optimization, optimize, ue5, third person, first person, shooting game, how to make a game, make your first game
Id: nKGF34Z5QTA
Channel Id: undefined
Length: 27min 58sec (1678 seconds)
Published: Sat Feb 24 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.