PCG Interiors Pt1: PCG Rooms for UE5.3 - Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this project is a start of a new tutorial series on PCG interior so we're going to start out by building a room that we can easily change the size of and control where doors are and then we'll be able to build off of this room onto more expansive projects later I'm just starting from a new third person project here and going to delete all this existing stuff on the level so we can start with a blank plate then we're just going to create a new folder called PCG that will keep everything that we're building in and we're going to start out with a blueprint actor class and that's just going to be bpor room and then we'll also have a PCG first uh we need to go up to plugins make sure we have procedural generation turn that on that should be the only one we need for this we will have to restart the project after doing that and now that we're back we can create the PCG graph we just want to create a PCG room and we're going to go into our BP room and then in this blueprint we just going to open the fob editor and we'll add a PCG set that to be our PCG room so in our BP room we're going to use this mostly to pass parameters into the PCG graph but we'll also get a few things off the parameters passed in so we can pass those into the PCG as well start out by adding a few variables here we want a wall mesh going to be a type static mesh object floor mesh and a door mesh we're also going to set a room size this will be the size that we want the room to be and that will be a vector 2D we'll make those all instance editable so we can edit those when we bring this into the level then we're going to start out with our floor mesh we're going to do a get bounding box this will give us the size of the floor mesh split that subtract the minimum from the maximum which will give us the size split that and that's going to be our cell size do a branch here and make sure this value is valid otherwise it's kind of useless recombine those they shouldn't have been split promote that to a variable called cell size we'll make that visible as well so we can get it in the PCG graph pile and save the room size it's nice to set that as an XY where X and Y are just the number of cells we want to multiply our room size by our cell size and we'll promote that to a variable called the extent and we'll use that in the PCG graph instead of the room size set that split it multiply them together and hook everything up now I just straightened out all the lines and then we'll pop over to the PCG graph we want to get actor property and we are going to get the properties that we just set up and we have to do that by name so we need to get all these with the same name that we set up on the blueprint and what I'm going to do here is I'm going to set up the out attribute name as the same thing and then I'm also going to rename these so we can see when they're in the graph here which attribute they actually are and we'll do the same for the room extent and the cell size so I should put these down here in a different order so I'm going to put the room extent up top here we don't need this in put right now we're going to put the cell size right after that we're going to do the floor mesh after that wall mesh and door mesh we're not going to deal with till later and what we want to do first is we want to break vector and we're going to divide it in half that's the full size of the room and we want to do the extent of our grid that we're going to lay the room out with from the center to the edge we divide this in half we'll get the dimensions from the center get a constant we do an add attribute and then we just set the number and then we're actually going to use this a lot I'm going to do here is I'm going to collapse this to subgraph and we're going to go into our PCG I'm going to make a new folder called PCG functions we're going to have a few PCG functions just going to call this PCG half go into that and get it so that it's working right we need to add the output here let's call out value set that as an attribute and now we have a nice little PCG function here that we can use whenever we want divide something in half oh I don't like the name of that input let's change that too so we're just going to duplicate this because we're going to do that for both the X and the Y we're going to remake that into a vector with make Vector attribute and then we're going to go ahead and create a points grid so the create create a points grid is going to give us a square grid of points that we can use to spawn things in with and that's what we're going to use to spawn the floor tile and build the other things that we need in the room we're going to take this this is our extense the cell size off the cell size that we set up in the blueprint and that'll create our Point grid copy this here paste it over we're going to divide the cell size in half as well and then we'll use an extense modifier we're going to take these points and we're going to modify their extent with this out value and we can call this floor extent now if we take our BP room go back out here to the map and we'll throw that BP room in here we can set our meshes can just uh use a generic floor mesh for now and then we're going to set our room size let's say 10x 10 and you can see it built the extent and the cell size and then we can go back into our PCG room room at the floor extent the create Point grid we want to uncheck the call points outside of volume by default that's on we're not using a volume so you want to turn that off inspect that with a we have the points coming out we have the points coming out of the floor extent and they have the bounds Min bounds Max set correctly if we look at this floor extent we can see the steepness is 0.5 that's going to cause issues later if we leave it so let's reset that we'll use Point match and set we can use that to set an attribute and we'll set steepness we want to set that to one so we just set that value here to one and then we can rename this to set steepness one so next um these these points that are created here are created at 00 0 so we want to move those over to our room location we'll use copy points to do that Source Point is the grid points the location we create points and then we create a point local at a single position 0000 0 that will be the actual location of this blueprint and we just need to hit points to create let's add a point here and that point this data this default data is fine so inspect that node and we can see we have a point created and the position is the position of our blueprint so then we just connect that up to our copy points as our Target debug that and we can see we have a big white grid here and what that is is that's all our points being created by our points grid and set to the size of our floor so that's ready to to spawn our floors in we want to add attribute and the attribute we want to add is just called mesh and we're going to take our floor mesh drag that over here so we don't have to run a long line right now and we'll connect that up and then we're going to static mesh spawner and we will turn this debug off and then our static mesh spawner we need to set to PCG mesh selected by attribute and that attribute we want is this one right here attribute name is mesh save that and you should see our floor is all spawned in at the size of our room what we want to do next is create the walls and to do that we want to create a spline around the walls we can create a spline from the corner points and to find those Corner points we'll use our Center position from this crate point and we'll use our room extent so let's get those a little more accessible we're going to take this room extent we're going to split that Vector again going to do an add here as well what I'm going to do is just add the center point to it and I'm going to grab these two and we're going to collapse to subgraph so we have a subgraph that we can work with here this going to be another function we're going to call PCG get Corners rearrange our pins here this will be our Center and this one the second one here is our room extent so what we want to do is come from the center and add on half the X and half the Y in each Direction and since we're going to use half of the the room uh we can actually go back to our main graph here we already divided that in half here so if we take this one instead of the room extent that will give us the half we need so to create a spline from this we want to we want to put these points together in the correct order we're going to go positive X positive y then we go positive X YX YX positive y so we're going to get our Negative X and negative y here do add attributes we have a constant that's going to be minus one and just multiply that by our X oops that's X we want y up here and we can change these labels to make this a little more clear so for this first addition this is our positive X positive Y and then we're just going to duplicate this and label each of these appropriately for all the different additions we need connect all the A's up to the center we'll just make a little room here and then we'll use make Vector to make all these back into vectors again before we add them connecting each make Vector up to its appropriate add for plus x - y - x - y and - x + y so now we have the Four Corners we're going to merge those and return the corner points as a point value and then this function is ready so so now we have our Corner points from our Corner points we want to create a spline and then we'll sample that sample that by distance and the distance we want to sample on is our cell size we want to break that Vector because we just need an X for our distance increment and then we can shrink that down got to go back into get Corners if we look at these right here we want to add to the position I forgot to set those to position so all these get set to position so I guess we have to set each of these individually now when we look at this [Music] bline debug this spline here can see the spline is going around the outside of the shape now which is good can see that the spline shape is incorrect we want this to be linear and closed loop so for this to work we need to set on this brake Vector attributes we need to set the output as distance increment and then on this flying sampler we want to check that that is unbounded now we're getting all these points here there we go so those are our points for our walls for the walls from this spine we want to go into a transform points we're going to need to rotate the walls 90° we're going to need a bounds modifier which we'll set up in a bit we're going to do this set steepness set that to one so when we want to exclude those from other paths we can and then we're going to do this at attribute mesh and instead of the floor mesh we want to grab our wall mesh which we haven't set up yet and then we want the same static mesh spawner with the mesh by attribute and we have an air here cuz we don't have a wall mesh yet so to create our wall mesh and I'm actually going to recreate the floor mesh as well cuz this one is way too large I am going to go into modeling mode and we're just going to create a box we're going to do 200 by 10 by 200 I'll do the floor first that's much smaller we accept that that will be created inside our third person cuz we're still in our third person map map generated and then here is that so what I would like to do is go into our PCG and just create a new folder in there called meshes and then we'll take that generated we'll copy it to meshes and then we'll rename this SM floor same for the wall we'll create another box this one we want to be 20 wide 200 deep and 200 high so let's do 200 wide and 20 deep I like that 20 let's make it 10 and there is a wall so in our generated we've got the wall copy that into meshes and rename that SM wall can delete these from the scene back up to our VP room we can change our floor mesh to SM floor and we can change our wall mesh SM wall now zoom in on that and we can see we have our walls and we see these are off all the way around and we can fix that back in our transform point point we just set this offset to 100 and 100 might need to be negative nope 100 is correct direction and now we have walls all the way around our room perfect we can go into this wall static mesh and we can set a better texture I'm going to import a couple of textures going to add a folder here to contain textures and I have a couple of textures that I've downloaded from poly Haven if you're not familiar with this website poly Haven you should check it out a lot of excellent textures you can also get textures from Pixel bridge but this is a good website to use I'm going to download this uh wood cabinet long that I think will match well with the door model that I have and the look I'm going for and then I'm going to get these Stone tiles out too and import those to the project so I use the gltf format and then you just drag in the gltf and it'll import those it's really easy to set up these days now that those are imported I'm going to go back over to the wall and just set that material and see how it looks and that's pretty good take a look at it in the scene much more interesting and we'll do the floora as well there we go nice realizing and looking at this with the textures on it's a little more obvious that I made these walls too short and if I pull Manny in here we can see he's almost as tall as the wall I'm going to go ahead and modify this wall make it a little taller we can use the modeling mode again to do that so pull that in and then I'll go into modeling and then after you do that if your texture looks stretched depending on what you used you can go down to the UV tab if you go project UVS set this into Box Mode you can modify the size of the box right here you can see this is 10x 200x 287 as the size of the box if I change this to like 200 here it's going to shrink that box and then it's going to have more repetition in that wall and you might be able to get a better look by changing this I'm going to keep it the way it was though but I wanted to mention that to create our doors we're going to do somewhat similar to what we did for the walls in that we're going to use a function first and what I want to do is copy this git Corners so I'm going to go out here to my PCG folder where I have that stored in PCG functions and I'm going to make a copy of git corners and we're going to call this git centers so I'm going to put the doors in the centers on each wall and then we're going to add some parameters to turn those on or off depending on which wall we actually want doors on this is our new get centers instead of making a vector of plus x - y plus X Plus y Etc what we want is just a single value here we're going to use plus X we use minus y here and then we'll have Min - x here and plus y on the bottom and so we just need to break the unwanted connections out here so we have just plus y coming in here on the bottom here we're just going to have Min - x here we're going to have just minus y and we're going to need another one of these up here where we're just going to have plus X and so these additions are the same we're adding to the center and we're just moving out to the wall so this will move out in the X direction to the wall and this moves in the y direction to that wall and these move to the opposite sides and then we're going to add some branches over here each of these is going to go into a branch and then we'll take this output to B connect those into the merge and the reason is because hidden in here is a an output to B setting so if this is true it's going to go out to to B otherwise it's going to go out to a so if we just don't use the a we only use the B this is essentially an onof so first before we proce Pro seed I want to fix this there's an err right here this this line shouldn't be connected to the half extent this should be connected to X so let's just fix that then we're going to go to our BP room and we're going to add in a parameter for each of the doors so we're going to call this door north and these are all going to be booleans and then we're going to go door east south and west and make those all visible then back in our PCG get Center we can get actor property and when we get that property we're going to want to get from parent instead of from self and we'll get the door north and we'll set that both as the property name the output name and then we'll also rename this node to Door North so that way it's clear and then we'll just duplicate this for the others and now we want move these up and hook these into the output to B make a little more room we can fit those right in the graph here we go out here to our main map we want to go down here and turn on those directions the next thing we want to do is we want to actually spawn in those doors at those locations and I had initially set this up with the door mesh here but we need this not to be a static mesh the door needs to be an actor I have a BP door actor setup and I will include a video here for you to set up that door a door that opens and closes which you can add to your unreal game it's easy to create download a door model glb format drag the door parts into your scene select the door parts actor merge actors merge save repeat for the frame delete from the scene bring the merged objects back in resize to the correct scale go into the modeling mode go to transform edit pivot set the pivot of the door frame to bottom the pivot P of the door to bottom adjust its location to the hinge location except bake transform open the door frame ENT Collision remove Collision then autoc convex Collision click apply save create a new blueprint actor and open it add two static meshes one for the door one for the frame set those create a blueprint interface function interact door BP class setting add interface interact interface interact under interfaces add a timeline door rotate double click a new float track rotate Z length to two right click the line add a key add a second key first key set 0 0 second key 2 minus 90 V craft drag the door in set relative rotation break the new rotation drag rotate Z to new rotation Z add a Boolean is open add a branch hook true to play to start false to reverse from end hook this up to not unfinished set is open to not is open character blueprint vent tick Vier Trace by Channel get actor location get actor forward Vector new variable interact range float 200 actor location to start connect the tick multiply forward vector by interact range add to location to the End branch to return value break the hit result pick the hit actor does implement interface the interact interface connect to another Branch promote hit actor 2 variable interactable object set that on true on false set that to nothing connect that to both falses content browser input actions add new action IIA interact in inputs IMC default add new mapping IIA interact map to e in your character IIA interact event get interactable object convert to validated G call interact drag the door BP into your scene and test now you have a door that opens and closes which you can add to your unreal game and we can use that door model here but we need to spawn actor and spawn actor doesn't let us pass in the actor like we can into static mesh spawner I'm going to look for a solution for that for a future episode for now we're just going to set BP door right here we'll get this working and then I'm going to look for options on the next episode see if we can get some difference in the doors we have a couple of problems here one is that our our doors are obviously merging with the walls and not cut into the walls so we're going to have to create a wall section here that cuts out this door but we're also going to have to exclude the door section from the walls and then we have doors that are facing in the wrong direction here we can fix both of those issues so let's go into our G centers first and let's look at let's turn off North and South it's north and south that are turned North is here south is here so we want to do a transform points and we want to rotate that 90° and then we should see those are facing the correct direction which is good now we want to go to our room graph and we want to exclude these door points from the wall points so we want to add up here we want to add a difference and our source is the modified points here and our difference is the door points and that should exclude those out but yeah as we see there's a big hole now so we have to insert this door into a wall so we put a whole wall section in here I'll show you how to do that now so we want to take our SM wall and we want to make a copy of that and we're going to call this one SM door wall bring our wall in and then we want to bring our door frame in and those have different angles so we want to rotate the wall to match the door and then we want to get our door lined up with our wall like we want it it's about like that then we're going to go into our modeling mode we're going to create a box that's the same size as our door if I put this box in here I can move it into position and that's about the right height for my door 205 now I can rearrange reset this depth and width that looks about right what we want is this to fit within the frame not go outside the frame not inside the frame so when this creates an opening it's within this door frame inside the wall and now click accept and then if we go into model we select the wall and then we select the box with shift and then click Boolean we'll cut a hole in that wall and then we can click accept then we want to go to our generator at we have this Boolean here we'll copy that back to our meshes we'll rename that all that SM door wall when we move this we rotated it and we see our pivot here is in the center need to go down here to transform we want to edit pivot we want to click bottom accept and then we want to bake the transform and accept now we go to our BP door add that static mesh if that's not automatically selected for you select your static mesh here and then move that into the right position for our door look around it make sure it's right right on both sides there we have it now we have that wall added to our door we can come here it does not show yet so we're going to force regen and it still doesn't show all right so I'm not sure why Force regen did not regenerate this wall here but I just change the size of my room like this and it fixed it so you might have to do that to get your room to regenerate with the wall we can see that we still have a gap here and the reason that's happening is because we're actually removing more wall than one section we've only put in one section for the door but we removed more than one section here from Our Generations so what we need to do is go into here and we need to take a look at this so if we debug this bounds all right I just had change this here to uh the correct selection sometimes PCG graphs are real finicky when debugging and it wasn't showing the points here now they're here that's way too big let's reduce that that to one okay now we can see our points here for our wall around the room here and we can see right here we're seeing both this extent and this bounce it's unclear which is which we want to see this as an extent okay that's helping and then this one well we also want to see this as an extent cuz what we want to see is what we're actually colliding between the two the extent on the walls is really hard to see cuz it's actually a little tiny line and we need to change that all right so a couple things we need to change here so this difference should actually be after we set the steepness that'll help out so let's move this the steepness setting to one we want before the difference that's why we were doing that and then we want this bounds to be a set and we want to set 00 100-2 and then 100 120 so we can see that hopefully okay yes now we are seeing those points they're too big so I change this bounds to all right 100 -10 -20 100 10 20 so we look at the size of this now it's super skinny what we want is for this extent to cover the wall of the door correctly and these extents to cover the walls correctly they are currently wide this way and skinny this way so we need to flip that so we need this be -10 here 100 here 10 here 100 this should give us the size of our wall approximately that way then this extents here we also need to set the steepness so let's do that now our steepness is one before our steepness was a half so we want that steep disc to be one that gives us a sharp edge between this extent and these we we want our difference node to be binary now that removes those walls sharply and then we want to set this extent that extent I am setting with the full cell size we want that to be the half cell size so I pulled the wrong line cut that this half the cell right there is what we want yeah there we go all right so now this extent here is the right size so it's not lined up with our wall so my BP door is off center I'm not sure how that happened that needs to be fixed going into BP door if we look at this is Center on the wall but we can see the location is at 48 45 which is not right I'm going to copy that value I'm going to say zero here and then I'm going to go to the frame and I'm going to say 48 45 and I'm going to do the same with the door and now now this should all be centered correctly file and save and now this did not refresh so I'm going to make this refresh by resizing and we're refreshed but we lost our debug points which is super fun there's our debug points so now we're centered up correctly with our extent we're still losing so we're losing two wall sections and we can see why that is so this this extent goes from here over to here and the next extent goes from here to here so we're overlapping with two wall sections and the reason is is because our room size is even we make this odd now our door is in the center and then if we shrink this bounds a little bit so they don't touch it's now solid cuz our true Center was in the middle of two walls and now our true Center is one wall so it works correctly we want the rooms to be odd in size so anytime they're even we're going to get that Gap so we want to make sure we always set those odd and then those will be correct so I am back after after unreal crashing and losing half the project and then rebuilding everything so if you notice a few little differences from cuts of the video I had to re-record a couple of segments and I re-recorded them from this version not the original version so there might be some minor little differences but everything is working in the end except for one thing I I want to show you if we go to our doors here they actually don't open and we need to change something so that they do so we'll go into PCG room to spawn actor right now the blueprint actors are collap we need them not to be merged so that they work interactively and then we play this again they should work correct correctly and there we go I was just doing some tidying up and final testing and I noticed a problem if you bring in the BP room right now it will hang the editor and I think that's happening because there's uninitialized variables what we should do here is we should check this floor mesh to make sure it's valid so let's add an is valid there cuz we really shouldn't do these calculations if it's not and then should go through your wall mesh and set a default wall mesh a default floor mesh and also I think set a default room size I just set 1 by1 same for cell size I said 10 x 10x 1 and then room extend 10 X 10 X 1 all these should get recalculated when you load but if they're empty I think it's causing a division by zero somewhere in the PCG graph and rather than throw in air it is just hanging the editor so make those changes to make sure your editor doesn't hang on you prevent some headache now that we have this working we can bring in several copies of our room and make this uh level more interesting I'm going to move the Z on these all down to zero so it's a little easier to work with and then U just set these up with different sizes oh another thing I'd like to do so we don't have this issue is let's let's check for that in BP room let's add a little function here at the beginning of the construction script to check if our room size XY is odd add a new function and we'll call that function is odd and what we'll do is we'll take our room size out we'll split that and then we'll do a modulo with two on a mod 2 if we have an even number it's going to return zero and if it's odd then it'll return one we want to do is equal to one and then we'll do our branch and false we want to add one to our room size and then we want to set that back to our room size again so we'll just add one to the X and set that back and then for the Y we're going to do the same thing so I'm going to just copy these these nodes over and we're going to run both the true and the false path to this second Branch so the wall y so move this down to the Y and then we want to copy this over and do this same add one and set on false make sure these are odd and then running that out to the to the return node on both paths and make sure we're setting y here and we should be set we also want to make sure on these sets that we hook up the other value so when we're setting y here on the second one uh we want to hook the original X up and then over here when we're setting X we want to hook the original y up otherwise we're going to end up setting these to zero and that'll obviously cause problems so make sure you hook those up as well to our construction script is odd probably give that a better name room size odd and so now our room size should always be odd so now now you can see we can successfully lay out multiple rooms and we can just drag in multiple copies or we can copy a room multiple times and set different parameters on those rooms in the next episode we're going to look at creating hallways between the rooms and spawning in props to flush out the contents of the room as well as looking at setting different room types so that we can have those rooms look more interesting than just empty rooms and be connected together as this series continues I'm going to show you how to spawn in rooms using PCG in a variety of different sizes and then create automated ways to connect them together and we'll come up with some different schemes of connecting those together I'll be they hallways like this dungeon layout here which is all done in PCG or with rooms buting against each other and connecting directly we'll have lots of different options so make sure you like And subscribe so you can catch all that content I'll see you in the next episode
Info
Channel: Raining Phoenix Games
Views: 3,311
Rating: undefined out of 5
Keywords: Unreal Engine 5, PCG, Unreal Tutorial, Procedural Content, Game Development
Id: L1sGInc9D08
Channel Id: undefined
Length: 36min 29sec (2189 seconds)
Published: Thu Dec 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.