How To Create Epic Procedural Dungeons In Unreal Engine 5 - Part 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys welcome to my video and my YouTube channel my name is Ronnie and today I will show you exactly how I created this procedurally generated dungeon that you can use in your game every time you press play you will get a new random dungeon and it's absolutely fantastic guys I will show you everything step by step I won't cut anything out and I will make sure that you see everything going into this dungeon I have searched YouTube myself for videos on how to make procedural Dungeons and I just couldn't find any good ones so if you are in the same situation as me and you can't find any good tutorials on dungeons this is the video for you anyway guys enough talk let's get right into it so sit back grab a cup of coffee and some popcorn and let's begin the [Music] tutorial okay guys so here we are u in a completely new project the third person template uh and I will just work from there to begin with I would like to look at something a little prettier to my eye so I will delete everything over here except for the Skylight and the postprocess volume delete this everything turns dark go into the Skylight uh turn off Real Time Capture set a specified Cube map and then select something you like uh like this one maybe yeah this looks better to me we can turn up the brightness to whatever you like let's just keep it like this for now you can play around with the light color if you if you want something a little warmer like this all right then I will need to delete all these things in here uh except for the player start and the the lighting stuff just delete it goodbye so now we just have the player start in there okay for this procedural dungeon uh we need two things well first we need a new folder called proceed Dural dungeon in here we need two blueprints which are just actors the first one is the master dungeon we just just call it Master room and we need a blue print called dungeon generator again you can call this whatever you want and these are just regular actors the master room is what we we will create all the rooms uh in the dungeon from it will have all the exits that will hook up to each other it will have the walls the floors the ceiling uh everything it will also have all spawn points I'm not sure we're going into spawn points uh this time but if you have spawn points it will get put into the master room um the dungeon generator is the one that will take the master room and Stitch everything together so uh in a random way so you will get a random dungeon every time you press play so let's start with the master room there we go let's add uh a cube for the floor let's just create some a basic floor and uh some walls and we will also start with a collision box box Collision this Collision box is the one that will make sure that rooms are not overlapping each other so we just call this [Music] overlap overlap box we call the cube [Music] floor let's scale up the overlap box 30 30 XY and C1 do the same for the floor Cube and they should be they should match each other right but they are not I don't know why they're not I mean why okay let's just make the cube so it matches um the Collision box so what is that 20 20 maybe [Music] again guys I'm not especially good at making tutorials so you will have to um deal with some uh fumbling around okay but this looks fine you can see here that the Collision box is a little smaller than the floor and and and we want that with don't want the Collision box to collide with the room right next beside it so we need the Collision box the overlap box to be a little uh smaller than the floor box okay let's get back in here so now we have a floor let's see if you can find a better material that is not so bright yeah that's that's better all right all right another thing uh I like to do for things like this is to put an arrow in here so I can see which way stuff are pointing right so we just move the arrow up wait is it it's just super small Arrow let's just make a super big Arrow like this in the center of the room so now we know which way the x axis is pointing and another important thing for this dungeon to work is that every everything needs to start from zero right now zero in the world is at the center of this room the thing is we need it not to be we need we need to do it like this so the center of the world of the room is at this point at the beginning of the room let me explain uh later on why I'm doing it like this uh so every room will have one entrance this will all make a lot more sense when we get a little further into it okay let's just make some walls let's just clone this box duplicate call it wall one and then we just need to scale it down so we can get some a wall looking thing I'm not sure how wide I mean you can do this exactly as you [Music] want see that's a bit too wide I think seven is a good 7.5 if we do it 7.5 then we can maybe we can get it get it to match up here like this is that right yeah all right let's try and go with this so now every opening will be like these two square wide I don't know all these terms but anyways just contrl + C contrl + V to duplicate it move it down let's go into perspective here and see see what we're doing all right these are cool walls contrl z contrl v to paste it move it take one contrl v contrl c contrl v rotate it and move it let's see from the top and see this is where things are getting kind of up for me right cuz I'm bad at math and you know getting this to match up I just don't get it so maybe seven and then we just need to move it in here like this see it's still too big so what do we do what six 6.5 ah man is that it yeah that that looks like that will work I mean this is why game development takes so goddamn long to do contrl c contrl v get it over here clone these contrl c contrl v anyways you can make your rooms as you want this is actually not the important part of uh this tutorial but now we have a room with the four exits right and here you can see on the Arrow this is the in in room this is where you will this part will be put on to the room before it right so the whole idea is we place this room down and then we will place another room and move it to one of these exits right these will be open exits that a new room can get attached to so when you spawn a new room it will get uh one of these exits that we will create later on and it will move the room to the exit and rotate it so it will be oriented the correct way so let's say you this is start room you go in here go to the left you get get through this door and you'll get into a similar room where the arrow is pointing this direction right does that even make any sense all right so we have our floor now and we have our walls let's just make a new uh scene over here which will work as a folder add scene let's just call it uh geometry folder right let's call these folders then we select the walls floor and drag it into the geometry folder right so now everything is under the geometry folder so we can just easily kind of close it so we can see what's going on here the overlap box we will also make a new folder for that one and and call it overlap overlap folder and we drag the overlap box in there let's just call it box one because we will maybe we will get more of [Music] these why am I calling it upap overlap box overlap folder there we go I'm sorry I'm an idiot just ignore that the cool thing about these folders is that in the blueprint we can get these overlap folder and then we can get everything that is in that overlap folder and we will do the same for the exits I mean let's just make that exit folder right now scene exits there we go we won't put anything into this right now also let's remember to uh get the arrow and set it to uh turn off hidden in game so we can see it when it spawns in the game so we can see what's happening and then compile this and let's just save everything and I mean let's just drag in the room here uh put it at zero uh and see if the player can uh can actually use it press play yeah the collisions and everything is working so that's all good and also I mean let's just make a material and uh make I mean this is just too bright uh dungeon material you should know how to make this material already right just plug some stuff in here in the roughness in the metallic set the roughness to one like this set a color and maybe just gray that would be fine apply let's go in to the walls and the floors and apply this material like this yeah that's uh that's that's more nice to look at at if I if I have to be honest here all right we have the master room let's right click it and let's make a child blueprint out of this and this will not be Master room this will be dungeon room uh one let's open it now we will make our exits and we will put them into this exits folder oh let's call it folder how oh I can't rename it I need to go into the master room and then I can rename it in here exits folder compile save and now it's exit folder right and let's just make the exits we can make them as arrows Arrow are cool because they're pointing in the X Direction which is very useful for idiots like me who doesn't really get the whole exess system and things are always pointing in the wrong direction and I don't know why so arrows are awesome Arrow one let's just call it Arrow one let's pull it out here let's make it a lot bigger so we can see what's going on we can change the color to I don't know Green cuz that's awesome let's put it at zero and let's rotate it around so it points out from the room that is our exit one copy paste it put it over here make sure it sits the correct exactly the correct spot here and rotate it and do the same for the last [Music] it like this so now we have three exits we don't want any exits right here in okay you can always already see I've placed the exit wrongly this is the entrance so we will just REM move this over like this and this is the see that is why we made that arrow in the middle so you don't get confused so this is where you get come into the room and then we have three exits where new rooms can get attached to and again we don't want any exits on the entrance room because we don't want another new room going back into the room that we just came from that will just be a complete mess so this is the correct way we can do it and what is super cool about this dungeon we're going to make here is that you can just if you don't if if you only want one exit right we can just delete these and it will only take this exit into account and these holes in the walls will be closed we will do that at the end of the dungeon generation we will get all these holes and we will close them let's undo this so you can make as many exits as as you want even you can make two exits on each side of the room and it will still work because the dungeon will just be checking the exit folder and it will getting all the arrows from that and putting it into a list and the new room will just be selecting a random uh Arrow from the list so it's super awesome guys so compile everything and save and let's get to the next part so this works so let's just delete delete the room again let's go into the dungeon generator here and let's just spawn that room right so on event begin play drag out type in spawn actor from class there we go then we go and find uh our room dungeon room one and then click the arrow so now it will spawn dungeon room one an important thing is that under Collision handling or right we need to select always Bor ignore collisions because sometimes unreal are just pushing things around if they spawn and they collide with something so um we want we are avoiding that by always spawn ignore collisions so where do we want the room to spawn let's just drag out the default scene route and type in uh transform World get World transform and plug it in [Music] here press compile let's drag in the dungeon generator here and put it in zero like this then we can go up here a where press play and we can click on simulate now it just simulates the game without spawning the player character and we can see what's going on so it spawns this room in zero remember that the room has its zero at the entrance all right so that is working that's awesome okay so the next thing we need to do when a room when the start room has spawned is to take all the exits arrows and and put them into a list let's just go into um the the the the the dungeon room here let's select the arrows here just click them on uh click off hidden so we can see them uh when you when we press play here so now you can see the exits like we're missing one why are we missing one let's have a look why is this missing oh because it's hidden I forgot to do it here all right so let's check again got cool we can see we have all the exits working so we need to go into the dungeon generator and from this room the dungeon room is in here it's in this node so we can get anything uh that we have in the dungeon room let's go into the uh master master room here we can get all this uh from here because the room is here so we can drag out here and say get exits folder so we're just getting the folder here and then we can get the children of that folder you see uh this is the exit folder let's go here in Dungeon room one and look at it the exit folder and everything that is in that folder are considered children and the exit folder is the parent I'm not sure if I ere explaining everything here but let's just explain what I can explain because I also myself hate to watch tutorial and I have no idea what's going on so now we're getting the folder then we can get children get children components with an S because they are more children and every every time we get something with s where there's more we get it as a list so now we're getting the folder we're getting all the children in the folder and we need to add this to a list all right so we can say um a pend array and that me EXP explain in a second and then right click this btom one and say promote to variable so we are making sure that it's the correct variable we are creating and let's call this exits list because this is a list compile so what is happening here we have a list there's nothing in the list you can see over here to the right that's the list is empty we're getting the folder we're getting everything on in the folder and we are appending it with this list which means that everything in in the excess folder are getting put into the list and also I think for some reason we need to uh swap these out so this one goes to the bottom and this one goes to the top uh I'm not sure how it works but I have just tried that it doesn't work the other way then we connect it here so every time we spawn this room we're getting all the exits and we are putting it into this list that means that there should be three exits in this list can we test that maybe press F9 see if it works compile press play there's nothing that is because I think we need another step let's just say print string and then remove this error thing and then edit F9 to uh make the code stop when it reaches this node let's try and see if if that works see we have three exits right now Arrow 1 2 3 in the list so that's awesome guys is just remove this print string again so another thing we can do that makes this a lot more clean is that instead of just going straight into event begin play we can delete that one we can drag out and write custom event and then enter and we will call this spawn start room so now this is an event and we can mark it like this press C and we can type in spawn start room what I like to do is give this a green color um like this put oh put the green color in here oh Jesus Christ delete this one so now we have a green color and then enhance the text a bit so we better can see it so this is spawn start room and to run this code we just drag out from begin play and then we type in spawn start room and now the begin play will play this one it goes into to this Noe which is this whole code here condensed into this one you can also drag it out from the left spawn start room in the event graph drag it out we have the same does that make sense it's just to clean things up a bit more okay so now the exciting part we need to add the next room so we will make a new move this up make a new custom event right click search for custom event presenter and we will call this spawn next room and now we have created the event we need to play it after the spawn start room so we can drag it in from the left uh spawn next room and plug it in after the start room so now every now everything we put in here will be played down here that's how custom events work and they are awesome when I learned how to use this everything becomes much more clear and and easy uh to look at right and it's much easier to organize if you make things in events like this you can also do it in the in functions which is basically the same the functions can do some more but then you need to open up a functions and go into a different you know viewport here to work with it and I kind of like to have it here so I can see what's going on so to spawn the next room we need to get an exit right so we drag in from the left the exit list with those three uh exits in it so we get it then we can get a random just type in random array item and you can right click the blue thing here and promote it to a variable and we will call this in the top right here we will call this selected exit point and then tie it into the custom event here so we're getting the list we're getting a random exit a random arrow and when we have gotten that random one we will set it and this means that this is the chosen one this node is that arrow that has been chosen for the exit so now that we have our exit we need to spawn a room so drag out here spawn actor from class just like we did with the start room and as before we need to set this one to always spawn ignore collision and see now we can select our room here we have two rooms the master room and a dungeon room one but we want to make this into a list and then we want it to select a random room from the list so right click uh on this class say promote to variable and rename it to room list and then we need to set this one over here I don't know what all this is called but there's a button to the right of the actor and select array and change variable type an array is the same as a list [Music] see now it it won't work in here I cannot put I cannot put a list into uh an actor cuz it just needs one and if this this is red you just hold down L and left click on it and it will go away so now we have a room list with nothing in it we need to get a random room from the list and we just do it in the same way drag out type in random random array item and then plug it in here in the class now if we have a list with many rooms in it will select a random room and it will put that room as the one that will be be spawned it's as simple as that compile and for some reason there's an error here which is the spawn transform um um you know for some reason it it it needs more information than that it it that this doesn't equal zero in the world uh so to fix that we just right click it and say split struct pin then we'll get the trans the the location the rotation and the scale and now it won't complain when we press compile see now there's no problems so I don't know what that's about so when this room has spawned right now is just spawning in zero in the world right I actually think we can just get the location uh anyways let's move on here let's get back to that we need to make sure that this room we are spawning is the master room so we track out here and then we type in cast master and select the master room so now we're checking is whatever we are spawning in here is this the master room or not and it is because we're only putting rooms in the room the dungeon room one uh is a child of the master room you can see it's using the parent is a master room you can see it up here on the right so the child are also using the master room which mean when we are spawning a child room it will work as the master room it knows it comes from the master room so let's right click as Master room and promote your a variable here and let's call this variable for latest latest room this is the latest room that has been spawned so what is happening here it's basically taking this uh whatever room has been chosen and it's setting that room meaning that we can get access to it we can drag in like get latest room and this is the latest room this is all this is the room in here we just have it in this small variable variable box all right Jesus Christ but I mean let's see if it works now I should just spawn a new room on top of the other room I don't know is it it's not H let's have a look that is of course we because we have nothing in the room list let's add the one room we have which is the just type in room dungeon room one because the list was empty it didn't spawn anything so let's try again play do we have two rooms we have two rooms and there's spawning on top of each other and that is awesome so let me just see here if I can let's just stop it if I can get the selected exit Point location right so I can get the selected exit point grab it from here and say get and then get get World location I'm getting the location of the exit point and then I'm D plugging it into the transform location here so now the new room will spawn at the selected exit Point location right it will have a different rotation always the same rotation but it should spawn in different place now let's see see is this the new one I don't know let's press stop let's try again see it's spawning this is the start room it has selected this exit room from the start and then it's spawning this room at this point Stop and Play see now it's selected this point here where it looks right so we got something working guys all right let's see if we can get the orientation correct also also I was dragging out this exit point I could also get it from here these two are the exact same thing so I can just drag it in here instead it will be the same thing but U I like to keep the strings short you know anyways so we set it as the latest room now we need to get the orientation actually can I can I also do actually I'm thinking about can I just can I got just get the transform get transform World get the world transform and get rid of this location and then right click and SA they recombine it to the transform and then plug it in this should work right so let's try and see yes start room new room selected this exit and it oriented itself correctly let stop play same thing here start room new room correct exit correct orientation so guys this looks like it works and it's it's better than my original dungeon which I'm making this from so I mean so far so good guys awesome work awesome progress okay next thing um we will clean this up uh a little more later on when we get stuff working we can do it like this so it looks awesome so now we need to get the latest room the the new room we need to get all the exits and put those into the list so the next room has even more exit to choose from all right so we drag out the latest room and we're getting it we could also do it here it's the same thing so get exit get exits it's in the bottom now we're getting the folder again just as before drag out type in get children components now we're getting all the exit arrows and again we will append append just means it takes everything in the list here and put it into another list and this needs to go into the bottom one and then we can get the exit list we have drag it out get it and put it in here and this list already have three exits in it now we get the three new exits here and we're adding it to the exit list so it should have six in it let's just test it out print we just need to test stuff out all the time guys F9 to stop it when it reaches this point and then put it in here oops so it will be the next thing that is played in the in our execution here all right compile let's see play let's see how many exits we have we have six three from the start room and three from the new room Awesome everything works as uh intended that's great guys okay let's just delete this again so now this is working awesome so let's just tighten it up a bit and then select everything press C on the keyboard and uh call it spawn next room and since it works working we're making it green and we are enhancing the the text here and line it up so it looks great here right looks awesome so another thing I think we need to do in here is that we need to when the exit Point have been selected we need to remove it from the list so it's not placing a new room on top of the same exit that has already been used before so we drag out from the selected exit point and then we type in remove so remove item in the array like this and then we drag out the exit list cuz we want to remove it from the list and plug in the list here and then connect these up so it oop so it's doing this uh before it spawns the room and I mean just because it has been removed from the list doesn't mean that this doesn't know where to spawn because we have already saved the selected uh point in the world right the all the exit points are still in the world I'm just removing it from the list so when we are using that list later on it won't get the same arrow that we had already used before and we might need to remove this later on because if this room doesn't work uh we don't want to remove it from uh the exit point from the list maybe we want to spawn another room on that exit and maybe that will work but let's talk about that when we get there just fix this up make it look great all right so the cool thing is now now we can just spawn endless rooms if I the idea is after this room has been spawned we want to spawn it again we want to get get a new room so spawn uh room spawn next [Music] room okay so now we are spawning the next room and this will maybe cause your computer to crash I don't know because now it's just spawning rooms endlessly right it spawn this room when that is done it goes back and play this whole code again spawns a new room puts it in place then SP wants a new room puts it in place right so this is a this will just carry on forever and that is not good so we need some kind of room counter that can uh you know count how many rooms we want in the dungeon and how many rooms we have left so it knows when to stop so let's do that and we need to do that before we press play otherwise it will just yet create an endless dungeon so for the room amount we just need to use an integer so we go down to the variables down here press the plus then we get a new variable we call it room amount and here where it says actor we need to select an integer that is just a number and it should not be an array so go over here to the right and change it to single compile then we can type in let's say 10 we want 10 rooms so when spawning next room we want to check if uh if we have any rooms left so drag out room amount so we're getting the 10 room number here no sorry guys we don't I don't think we need to do it here we need to do it over here before it spawns the next room so drag it out room amount get the room amount when this room has been spawned and everything is good we want to subtract one room from the room amount so drag out uh click the uh minus or subtract button on your keyboard then selit subtract and type in one so now we are subtracting one from the room amount and then we need to set it to the new so drag out the room amount again and select the set room amount right so we're getting the room amount we subtracting one and then we are setting it again so now it's only nine this is the new we updating room amount uh file here this one this one and this one is the same this one has 10 when we have to subtract one then it has nine which means this will turn into a nine drag it in [Music] here when that is done we need to see if we have uh more rooms than zero here [Music] so we are getting the room amount again we get it and then we want to see if it's bigger than zero so type in this uh big type in this I don't know what this is called in English you can also just type in Greater maybe yeah greater if it's greater than zero uh hold down B and left click and you will get a branch you can also right click type in Branch here same thing put the red one into the red one drag this back here so if the room amount is greater than zero we want to spawn a new room if it's zero if it's not not greater than zero we will do nothing we won't spawn any new rooms we will stop the generation press compile and let's hope everything is in order press play we should have a dungeon now with 10 rooms or maybe the mass probably don't work 1 2 3 4 5 6 7 8 9 10 10 rooms and a start room all right press play again we get a new layout and all these exits you see here they are all getting added in the list so all if if we spawn a new room right now uh then it has all these exit points to choose from for the new room does it make sense getting a random dungeon this is awesome guys the thing is that we might not see it here but um let's say it's adding a new room to this arrow and it places a new room here then we get a new Arrow over here and then if it selects that arrow and places the next room it will lie on top of each other because we have no way right now where we're checking if any rooms are touching another room or overlapping another room and we want to make a rule that does that if a room is getting placed on top of another room or hits another room then we want to delete that room and we want to try and uh select a new exit uh somewhere else and place the room [Music] there that is the the harder part to do but that is super important okay so that is just super cool for now let's fix the overlap thing it's not really a problem now but we can also if you go into the dungeon generator go to the room amount you can set it to 30 right compile and then we can try again and we will get a dungeon with with 30 rooms some of them might be overlapping now we can't really see it because they all the same material so there's not really any flickering or anything that will tell us that anything is overlapping but they're probably are you can see here guys I found a room that is overlapping room number 12 and room number 18 are on top of each other so that is not good and we need to fix that okay so we need to fix this overlap thing just go in here make this pretty like this let's go down here let's make a new custom event right click custom event and we call this add overlapping rooms to list so now we want to figure out if the rooms are overlapping any other rooms so drag out the latest room the latest room is the newest room that we have placed we want to check if that is overlapping with anything which is why we made the overlap box so drag out from this room type in overlap H what did we call it folder right folder get overlap folder just as we did before then we're getting the children get children components so now we get everything in the overlap folder and now we have to do something called for each Loop and that is just something I don't really get and and don't like because it's confusing as hell so drag out from this array type in for each Loop this means it will do this whatever we put in here it will do that for each thing that is in this list each of the children will be going through this code so we drag it in here and what do we want to do for each of them we want to get the box uh box Collision component let's go into the master room here this overlap box you can see if you hover over it it says uh box Collision that is that is what this component is called so we go into the dungeon generator drag out here then we need to cast to that box Collision box component okay so here it's called box component um guys confusing as Hill but we select this one and we're getting we're making sure that this overlap box is a box component I don't know why it says Collision here but when it's a component so I'm a bit confused on some things but after hours of fiddling around with this this is the solution all right so now we want to get anything that this box is overlapping and put that into a list so we drag out we say get overlap get overlapping components we want to see if it's overlapping any other box Collision components and we want to put those into a new list so we type in aend aend Array and we need to plug it in the bottom one and then alt left click to remove this one and then plug into the cast over here and then right click the empty uh pin thing and say promote to variable and we will call this new variable overlapped list so everything that is getting overlapped is getting put into this list so we're checking the box in the room if it's overlapping with any other box then we will put it into the list if it's not overlapping it will not put anything into the list the reason why we're using it for each Loop here is because in the room if we are adding another overlap box right let's say you have a room that uh let's just copy and paste we have a room that goes like this right you cannot get a box that covers this so we need multiple these overlab boxes to check so we can have more Olay box overlap boxes um in in one room that is why we're checking all the overlap boxes here and if they're overlapping anything we put it into a list and then later on we check if is if there's anything in this list we will delete the room because that means it's overlapping if there's nothing in the list then just place the room and move on okay we have I don't think we have any real way of checking if this is working so let's just uh caption this and call it check for overlapping rooms make it bigger so you can read it so we won't color this green because we doesn't know if it works yet so now we need to fire this off so we getting this custom event we just made drag it out from the LIF add overlapping room to list we will run this code which is all this up here condens down to this one so we drag out and we make a branch a branch is just checking if anything is false or if it's is if it's true so let's get the overlap list we just created let's see if there's anything in the list so drag out type in empty so if it's not empty if this list is not empty we will go and delete stuff if it is empty which is this one we will move on okay so let's see if it's not empty that means it's overlapping then we want to destroy the room destroy destroy the actor what actor do we want to destroy we want to destroy the latest room which is the one that is overlapping another room so that room is getting destroyed but then we don't want to stop the Labyrinth or the dungeon right there we want to keep going make a new room so we drag out here type in spawn next room we do everything again if I click on this you'll see we getting new exit points we are spawning new room all this stuff we adding exits to the list we are subtracting one from the room of course if a room is overlapping we don't want it uh to remove a room uh from the room amount right because the room is not getting placed it is getting destroyed so we don't want to we don't want to subtract one right here but let's figure that out later on another important thing we want to do here we want to clear this list so it's empty for when a new room is spawning it so it doesn't just add in all these Collision boxes every time a new room spawns every time a room spawns and it's fine then we need to clear the list so it's back to zero so we can get some new colliders in so we can check those and that's easy to do we just drag out the overlap list get it drag out here and say [Music] clear and then just make room for it put it in here on the true so before destroying the room it's clearing the overlap list so we can get the next room that is spawning will put its overlapping boxes in the the list and you can copy this copy paste and then we need to do the same if this is false we need to clear the list no matter what if the room stays we need to clear the list if the room is destroyed and we are starting a new one we need to clear the list so I think we can actually go up here get this where we are subtracting from the room amount you can cut it out cut [Music] crl x connect this up and then we need to put it down here for if the room is successful then we will subtract one if the room is getting destroyed we will not subtract it from the room amount right because we will be getting a new room to test if that will work yeah okay so what's next we need to play this somewhere this needs to go in somewhere but where do we need to plug it in uh probably before this so the room is getting placed and we're getting all the exits we want to wait with that also move it over here can we make this a little prettier with some more space so when the room is placed and it is moved to the right uh location and all then we need to check if it's overlapping anything we can we can make a new custom event here custom event oops and we will call it check for overlap check for overlap why can't I spell overlap today that is nuts so when this one is getting played it will play this one which is this code up here when that is have been running then it goes on to play the next part so we need to fire off this check for overlap and I think we need to do it in here so grab it from the [Music] lift and plug it in so if all this is good we're moving on but I'm doing something wrong here I think we need to put this code here uh down in here somewhere right so let's say the room is successful then we will be adding okay so cut this out we will add this down here we will subtract one room and then we will add all the exits to the list so what's happening up here let's remove this one we don't need to spawn next room because we will be do we can do that down here [Music] too copy this over like this so if the room fails because of overlap it clears the list it destroys the room and it spawns try again spawn a new room if the room is success successful it clears the list subtract one from the room amount it adds all the exits to the exit list and then it will spawn the next room but we of course we need to check if uh the room amount if we have anything more left in the room amount so copy this down or cut it out and plug it in here before we spawn the room we wants to check if there's uh any more rooms we want to spawn if there is true we spawn room if it's not true we stop the room generation I think I mean right now I'm just improvising delete this one but I mean it should work that's a very that's a chance I'm screwing up the whole tutorial right now guys that is kind of a uh yeah we'll see let's see guys if we can get it to work this is exciting exciting times play [Music] oh okay uh I think I know what the problem is it that is the Collision so in the room we get the overlap box here I think that is just colliding or overlapping with with everything so go down to the Collision here Collision presets generate all have event yes can step on no uh let's set this to custom no physics Collision that is fine only overlapping uh and it's only it's overlapping with everything right so the thing we need to do we need to go in and make our own overlap channel so go into project settings and go down to Collision and then we need a new object Channel add new object Channel we will call it uh room overlap room overlap and we will set it to ignore press accept then go back to the room Master room I think um and then over here we can set the type that this overlap is it's not the why is maybe I need to refresh all notes maybe oh there we have room overlap so we set this to room overlap now this overlap box is a room overlap and click off everything so it ignores everything except for room overlap we will set that to overlap holy that's a lot of overlaps so now this box should only over AP with room overlap which the box is set to so it should only overlap with the you know a similar box in another room let's see if it works better now okay play yeah something infinite Loop so okay let's try and put in a delay here so we can see what's going on delay 0.5 so every time it has sit down a a room uh it will wait a half second before it tries the next room let's set the room amount down to 10 see if that's even possible play [Music] so now it's deleting rooms and it's placing rooms is that it 1 2 3 4 5 6 7 8 9 10 and a start room looks like it works let's try again yeah you can see there's no arrows on top of each other sometimes there is but they're getting deleted 1 2 3 4 5 6 7 8 9 10 11 yes something is working so what if you remove the delay okay we just get a dungeon so looks like the dungeon is working to make it look cool we can just make a short short delay like two 0.2 see now you can see the generation which is awesome and we're getting 10 rooms plus a start room all right let's try and make an even shorter delay and then let's try and put in some more rooms or I mean some more room amount 30 let's see if it still holds up yeah looks good so I'm I'm just guessing we have 30 rooms here 31 rooms yeah that's great guys so this down here is working this is working let's put it in green this part down here is also working it seems delete o delete if over overlapping delete latest room if overlapping it is green bigger text okay guys I do think that we need to move this where is this one oh I have unpluged it [Music] we need to move this cut it out and put it down here where we are uh sure that the room is working just make some room for it down here paste it in like this and this will be this will be the selected exit point when we are certain that the room is working we will remove the exit point from the list because it means there's already a room there for the next one let's see if it give us gives us any errors looks good and you can see the the I mean the the dungeon here is just getting completely randomly generated there's no structure in it at all just selects a random exit point and places a room so and you can see when you have a ton of the same rooms with three exits it turns into something like this but I mean let's try and make a few different rooms and put them in so we have this room one with three exits let's duplicate this and we'll just call it room two then we can go in here and oops my bad what just [Music] happened holy uh okay that looks okay that looks right so for room two we can kind of just remove the ones on the side so no rooms can spawn here and we can just close these uh walls these holes in the walls something like this and I don't know five 5.5 yes works copy paste it over so now we have this type of room compile save everything so this room two we need to put it into the room list so select the room list from the left open make a new one and paste in room number two so let's see how that works see we have one here we have one here we have a lot over here so we get these corridors it's really not that different is it so the thing is we can also go into the dungeon generator put in more of these room too right so just kind of duplicate it a few times so now there's a much bigger chance that these rooms will get selected see we get get a lot more corridors now [Music] let's go in and make let's make a few rooms that only turn left and only turn right so we have so room number three let's make it so it only uh okay let's not duplicate that one delete it again and take room one duplicate this one and open this one room number [Music] three delete the front arrow and the right arrow then fill out the holes oh 5.5 5.5 five what oh man I mean this coordinate systems anyways now we have a lift room let's clone this duplicate and make a right room right so move this one over here like this and move the arrow over here again you can add as many arrows as you want just make sure you have an exit so let's put in room three in the generator and room four in the generator compile let's see what we get same thing let's try again well it it is a procedural generat dungeon there's no denying that ah now it lacks some exit points because it ended up yeah closing itself in because it it it lacks exit points that is not a good thing I've never seen that before actually maybe just make sure that you have enough exit rooms all right just maybe plug in some more of these rooms number one so we have more exits to work with I mean it this is by no means a perfect dungeon at all it it does have some problems but the this is a really good start right to to get you to get you going so now we need to close off those exits right so when the dungeon when the dungeon is done we get all these open whoa these open exits and we want to put a wall in there so the dungeon is completely closed off and uh let's do that now so in the dungeon generator let's just make it a little more pretty we will make a new custom event custom event and we will call it close holes and let's check if um selected selected exit points are getting removed oops so find references he setting the exit Point here we're getting it for the position of the room and then we're removing it so it is getting removed when a room is successful so that's good let's go down here so everything let's get the exit list here everything that should be in the exit list now are open holes but of course we also get uh let's see here room amount let's let's just turn it down a bit uh so I can show you here we also getting holes here in inside the dungeon this holes need to get close to right this one needs to get close to what I'm trying to say here is that there's an open there's an exit um point right here that has not been removed because there's no room has been placed on it right this room here comes from here and not here so no room has been placed on this Arrow uh but we are going to put walls there anyways so let's get back to the generator so exit list we will make a for each loop again these damn things uh so on any every exit we just want to spawn an actor uh wrong like this spawn actor from class and we will get the transform here World get transform get World transform here from this exit we are finding and plug it in and remember always spawn ignore Collision compile we need something to to spawn so we will make our uh what we call it make a new actor here blueprint class actor we call it end wall I mean you can call it what you want doesn't really matter open this we can uh take our dungeon room and we can grab this piece for example copy paste it in here and move it to zero and set the rotation to zero but this this has the size we want uh for the wall holes move it up so it's at floor level compile it and let's plug it in here select the end Wall go to dungeon generator it's getting a little confusion now guys I'm sorry about that but uh again tutorials is not my Force plug it in here inv wall compile we need to play this close holes and we need to play it [Music] uh where do we need to play it we need to play it down here when there are no more rooms to spawn type in holes close holes this should work when there are no more rooms in the room amount to spawn we will close all the holes let's see if it [Music] works see it closes the holes that is amazing guys we just need to move it in place so we need to move it a little up and a little back I think I mean this is just you know random up and back so it's on the line let's see if that's enough it is it worked this this is the start room you need to put in a wall here in your start room that nothing will spawn from this point uh so you know you will always start with your back against the wall in in this uh maze there's no I mean you could do the same but it's easier just to make the room with no holes in it the start room here we can even you can put in a small delay so we better can see it delay 1 second compile play see all holes are closed and of course in your labyrinth you need to make the rooms uh so they kind of make sense and the end holes that is getting put on needs to fit in with the rest of your dungeon design that of course that makes sense this is just clean cubes I'm using just to show you how to make this that's it guys we have a finished dungeon here the last thing you might want to do is this is the last part in the creation right you can make you can make a Boolean called dungeon complete compile it that is set to off the dungeon is not complete so when these all these [Music] holes are put in then drag out the dungeon complete and set it here and put a check mark in it that means the dungeon is complete you're going to make a print string that's this dungeon complete so make it a bright color here make it last for 60 10 seconds right let me play dungeon complete and that just means you can get this on other blueprints like on your player character if you want to wait with spawning him until the dungeon is complete or maybe you want to fade in the player UI uh but only when the dungeon is complete then you can have a loading screen you can remove the loading screen when the dungeon is complete right that that's kind of how it works so you check if the dungeon is complete before you you spawn the rest of your game and of course we need to just make this pretty so close holes green because it works size 30 so you can read the text and there we go and it it it doesn't look too bad does it just align everything so it looks awesome put the event begin play at the top don't put anything around this so you can easily spot it and event begin play spawn start room start room here when that is done spawn next room and that will just Loop uh and fix all the collisions and uh when there's no more uh numbers in the room amount the dungeon will set itself to complete that's it and I'm sorry if this tutorial was a little messy I mean I'm still trying to to learn these tutorials but and it takes a long time to make and uh I was fumbling around in the middle and stuff is not working but I again I think it's important for you guys to also see when stuff is not working and you will see how you can kind of solve it I can see here we also need to delete this one not using it just make things pretty right remove all this space make it make it easy for you to understand where to find things divide it up into these uh custom events it will make your life much easier I mean the thing is right now what you need to to do for your game here is to go in and make more rooms right let's make for example let's clone room two here duplicate let's make a hallway room right that hallway room so just go in here make the walls shorter let's just try and do it like this [Music] like [Music] this right make this smaller remove these oh that's another thing oh that's important um all these walls and and because these walls are in the master dungeon room here that means we can't delete them which is a big problem so we need to go in let's see here room one let's copy all this all the walls on the floor copy it go back to the master room delete it from here compile this should be all we have in the master room you can delete the Arrow when you don't need it anymore so we go back into our rooms room one and they're gone so go into the geometry folder and paste it it's not in the geometry folder but uh just move it down or don't doesn't really matter where it is um let's just delete these things we're not using so room two see everything is missing now except these new ones I made so geometry folder paste it in put it down in the geometry folder so that is room two and I know this is this is annoying but um it's just important paste it drag it down to Geometry folder like this and since we already put them in it's not that big of a deal dungeon 4 paste it move it to the folder and it all looks right dungeon room five uh paste it move it to the folder like this and now because these are not part of the master room anymore now you can delete them if you [Music] want let's move it back in place here for our hallway room so delete these move these [Music] out like this and what is this 7 7.5 [Music] 7.5 again we can make duplicate this we can make some uh pillars out of this duplicate them move them around I'm just doing this to try and show you that the rooms you're making for your game here will be awesome right the more rooms you make the more special the dungeon becomes and the more variation you will get into your dungeons also this one need to scale down to and it needs to kind of go in it cannot stick out so compile get this dungeon room five go into the generation room list let's remove let's let's put it in here 1 5 2 3 4 we should get some hallways now we got one hallway and as you can see already now the hallways are making the dungeon a lot more interesting let's just we can clone it just clone the hallway so we have more of them in the list and see did you see there was a hallway right here that got deleted that's not a lot of hallways holy and even the hallways are getting these end holes repaired that's it guys that's y we haven't even tried to run around in the dungeon yet see what a pretty dungeon [Music] the last thing we need to do guys is to make a fail safe for the dungeon so it will prevent it from uh if the dungeon breaks let's say it after the start room it spawns four uh rooms that can only turn left that will mean it will be like a snake that turns around and it will bite itself in the tail right and and it won't be able to create any other rooms because there are not any more exit you know what I mean and if you're unlucky and there's no more exits for the dungeon rooms to spawn it will just delete the rooms and try and spawn them again and delete them and try and spawn them again and it will do that uh for eternity so we need to make some kind of timer uh when the dungeon starts uh the max amount of time you want to spend on creating the dungeon and if the dungeon takes longer than this time it will reset itself and start all over with a new dungeon and hopefully get a better result this time it will just basically uh prevent your game from crashing and you have to uh exit out of the whole game and boot it up again uh to try again so that's what we will be doing now so we will make a new custom event custom event call it start dungeon timer and we will will make a timer by event set timer by event this timer will run every second and it will be looping so when this is fired off this will trigger something every second so drag out here let's make a custom event and call it check for dungeon complete and now it's a good thing that we made that dungeon complete Boolean early on so let's just make a print string here print string so we can see if stuff is running let's type in running timer and we will have to start the timer down here in the event begin play so we can just start the timer after the first room has been set uh where is it over here start dungeon timer drag it in plug it in here with the rest of the boys and now we can see here this just oh another thing while we're here get the room amount click it and over here to the right click instance editable and expose on spawn this means that we can select the dungeon generator over here and we will have the room amount right here so we can just change it here instead of inside the generator so now it's 30 but it will still be 20 in here right so it's not the same thing if you want to make it back to the original just click on this Arrow it goes back to whatever it is set to inside the dungeon so so set it to 30 we'll see if the print string is working yeah see it's running timer every second it prints out running timer the problem now is that we need to make it stop when the dungeon is complete or if it takes too long we want to reset everything so we can start by uh stopping the timer when if the dungeon is complete so on this time by event drag out from Return value and promote to variable and this is something I don't really understand but it's something uh I'm doing in my game The Adventures of G when I'm creating my dungeon in there so call this uh timer handle whatever that means um yeah who knows then go down here to where the dungeon is complete and drag out the new timer handle get it and then drag out and say clear clear and validate timer by handle no idea what that means but it will stop the timer if the dungeon gets it complete right if the dungeon gets down this road and completes it itself so let's see if it works time was running dungeon complete and the timer stopped running so that's a good thing great looking dungeon right so let's go back into the generator now we want let's make a branch here hold down B left click make a branch so now we want to get right click and say get game time game time in seconds also I'm not really sure what this is I think that is something that runs when you press play or again I'm not sure guys but if this one turns out to be greater or equal this number let's say five let's just get some more space [Music] here right if if the time has been running for 5 seconds or longer it will be true and in this case we want to open level by name I mean this is a kind of a hardcore way of doing it so we're just closing down the level and open it again uh I'm sure there are different ways of doing this but uh when you close the level down and open it again you're sure that nothing is Left Behind in the level where that you have no idea about or can control right so in this case the level is called third person map let's see if it works if the timer is greater than 5 Seconds let's just set it to two and then I have two seconds to create a a 30 room uh dungeon yeah see it cannot place down the 30 rooms before the 2 seconds is up so it it's keeps loading the level again and again and this is what we want now we can control how much time we want the dungeon to try and uh complete itself so stop it let's see here let's try and set it to I don't know 15 seconds so now it have now it has 15 seconds to complete itself it did it completed the dungeon under 15 seconds and it stopped the timer and now we can just play let's try again it completed the dungeon does it have 30 rooms it has 30 rooms so maybe maybe it will complete the dungeon in maybe 8 [Music] seconds yes so it's about finding you know the max amount of time you want to spend in the loading screen sometimes the dungeon takes longer if it's if it keeps overlapping other rooms and it will recreate new ones but another thing we want to do here uh first of all we want to make this a variable promote to variable and we will call it Max dungeon time and that is eight right now so of of course you want want to set this dungeon Max dungeon time you want to increase it if you are increasing the room amount for the dungeon I mean and you can do some calculations so you you kind of um you just multiply the dungeon time with the amount of room you have I mean something like that but so let's clean this up make it pretty Caption This call it dungeon Tim it works so there we go we can get this out of the way and move it at the top so we always have begin play at the top and now your dungeon should be working you just have to balance the max dungeon time with the room amount I think this is enough guys this is a very stressful for me especially at that point where everything up but uh we got it fixed and it's absolutely fantastic that's it guys that is how I create a procedural generated dungeon I hope you enjoyed the video I hope you got something out of it I'm and I'm hoping you will create some awesome dungeons using this system and even better I hope you take it to the next level and do something that is even more awesome right for your game so if people like this video I'm considering making a part two uh where we can talk about how to spawn different things uh in the dungeon enemies gold coins Treasure Chest things like that let's talk about that if we get there anyways have a nice stay guys and see you next time [Music]
Info
Channel: REE ANIMATION & GAMING
Views: 27,521
Rating: undefined out of 5
Keywords:
Id: 4ddbnQIuwAM
Channel Id: undefined
Length: 108min 30sec (6510 seconds)
Published: Wed May 22 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.