Realistic PCG Buildings in Unreal Engine 5.4 - Tutorial Part 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everyone today I'll show you how you can generate buildings with the PCG craft system in Unreal Engine 5.4 you can use this uh method for creating different sizes of buildings with different features on each building to have your city look more randomized and more natural I have as well added uh decals with graffiti elements or with uh leaking uh moisture from random windows on the building walls so if I select this building I have different variables to control the size of the building in each Direction I can control the number of fours and I can randomize different features on the sides for example if I want to not have doors on this building I can enter zero now I have only the garage doors if I want every item on the first floor to be a garage door I can enter one or repeat them each second wall or as I had before I can have couple of doors and then random amount of garages on each side on the main floors I can have different type of windows so I have this double window and the single window if I enter zero I will not have the double window again for the for this uh window with the closed up bricks type I can also have it randomly placed or in any type of pattern that I want if I can have all the windows the same let's say I'll go back to repeating the double window and the single window and on the last floor I can have the roof Windows which have a special type of door for the last floor this is based on the quick cell NE Baro building type two this is the type one nail barck building so if you create this PCG graph you can easily then swap the meshes and have a different type of building with the same controls so I can increase the number of fors or decrease them and I can randomize some elements on the side of the building so I can have different type of elements on the first Flor and so on let's go with the first type and then I'll show you how you can change to another type of building with another set of meshes from quicksell Mega scans it's a bit of a long process to create this PCG graph so maybe it will be split in couple of videos to not be too long but let's start and we'll see how it will go I will now delete everything in this scene and we'll have a fresh start now let's start with creating the blueprint let's right click in the content browser create a blueprint Quest choose type of actor to be able to place it in the scene let's call it BP building and inside this actor we'll need to have a PCG element let's create a PCG component and for the PCG graph field here we need to create a PCG graph to connect it so right click into your content browser go into the PCG menu and choose PCG graph let's call it PCG building and let's drag this PCG graph into the component in the blueprint that we just created drag this into the graph field compile and save this building blueprint now when we create the building we need to have control over couple of uh variables so let's create the variables now so it will be easier later to use them let's start with creating the variables for the size of the building click on the plus sign next to the variables field and let's start with the WID it should be an integer value let's create another variable call it length it will be an integer again another one height it will be again an integer now let's create some variables for the generation of each floor of the building so let's click on this add variable again and create a wall length variable let's choose a FL type for this create another one which will be pure length I'll show you now what is each one representing create another one corner length and one called cink height so having these variables will help us create a different buildings with just one blueprint so make all of them public by clicking on this I to be able to use them in our PCG graph compile this blueprint and save it now let's drag this blueprint into our level and let's move it into the position 0 0 0 this will make it easier to generate the building and then we'll modified to be used on any location that we have we will go now into the PCG graph to create the logic that will create the first floor and we'll reuse the this for every other floor of the building so we'll create it as a subgraph but let me quickly explain what we will do let's choose the meshes that we will use for creating the building so I'll start with using this wall I'll add a p between each wall and then as a have for example this wall I'll need a corner element and then the other side will start from this corner elements into the other direction we need to do this for the all the four sides of the building and have it procedurally generated by the settings of how much we want the width to be and the length for the building I wanted to show you this in order to explain a little bit more uh visual what we'll do right now let me add one shape to explain what's the logic that we will be using creating this wall so let's say this is the PCG point that we are generating with our PCG graph I'll scale it a bit to be more precise so when we create a PCG point we will bone from it this wall and this pillar we'll then find only the corner points for our building we'll remove the pillar from there because we only want on the edge to spawn this wall and then when we remove this pillar we will spawn this other type of pill for each Corner what is also important to note here is that when you're using this uh quick sell assets if you go and place this wall you will see that the pivot point for the wall is here in the corner not in the middle and by choosing to place the walls from the middle it will be a little bit easier to to keep up with the mat needed to do the four walls so what we'll do is we'll offset the wall by the half of the length in order to be placed directly on top of this point so this wall if you hover on the on the model itself you will see the approximate size on the bottom of your screen which is 400 units wide so this is the length of the wall which we'll be using for this building for the other pack of the ne Baro building one the sizes of the walls are 350 so we have this in a variable R building it will be different but for our current one it's 400 so we'll start with this number and you'll see how later we can change it for any type of building so by having this wall 400 units wide we need to offset it by by 200 in order to be in the center of this PG point also we'll be placing this P which is 75 units so we'll actually need to offset by the half of the total length of this so 475 half of it we have 232 or something like this we'll calculate this and offset by half of this width and that way it will be more easy to place each element on the side of the wall and for them to be connecting properly at the edges so let's delete this example meshes that we made and let's start with editing our PCG graph let's open the PCG graph that we just created now let's start with creating the logic inside to create the walls first let's create a point grid so start typing Point grid and choose this create Point grid note let's set the GD extends and cell size based on the sizes of our wall and P so the wall was 400 units and the P was 75 so let's add them together and this will be the cell size for x and y and for the Z the Wall height was 400 and the GD extends let's for now make it 475 by 3 this is a great way to set your numbers by writing expressions in the fields so don't need to calculate the proper size just write the expression that you want so now this grid will create point with this size that we set here in the area that is covered by this uh GD extend actually for the vertical we can just set it to 400 because we'll have only one for for now we'll make this sub grid to create each Four Points so let's debug this create points grid field let's zoom out a little bit so this points grid is spawning points into our level there with the size that we set up here and covering this area let's scale them down a bit by creating a bounce modifier because now they're overlapping each other let's scale the Bounce by 0.5 in each Direction now let's debug this by selecting the note and clicking the D key on your keyboard for debug or manually enabling this debu option for each note you can preview the result of this note in the viewport so now I have this grid of points it's created with the size of the wall plus the pill and then scaled to half of the size by this modifier so they're not overlapping now what we will do to create only points on the side of this uh grid we'll move our points half of the size of each cell in the One Direction and then in the opposite direction and we'll just delete the points that are overlapping each other in the middle so to do this we will create transform points note half of the size is 47 25 / 2 we will move them to the one side by this amount I'll copy it again move them down the negative amount and then rotate them because the walls on the other side needs to be facing the opposite direction so one of the transforms is positively moving to the right and the other one negative moving to the left and rotating them to the opposite side now let's do a difference note as a source we'll put the first set of points then we'll connect the second one for the difference let's stop debugging this and start debugging the difference you will see that now we have only one side of the wall because this is our original point set this is the one that we are moving to the right if I enable and disable the debug you'll see that it's moving the points to the right if I enable and disable the other one you'll see that it's moving the points the original points to the left so when we difference these two sets we are only getting the ones that are not overlapping in the middle so let's copy this difference note let's change the source to the second set and the difference to the first set so now the second difference is actually creating the other side so if we debug both of them now we are seeing that they are creating the two sides of our B building so we'll do the same for the other two sides of the building so copy the transform points and the difference nodes you can connect them in the same way first one for the source in the first difference and for the difference in the second difference note and the other one for the remaining pins now the transforms needs to be in the y direction and I'll rotate the first set 90° because on the other side side of the building we need to have the walls facing the other way not to be parallel with the ones on the sides for the other side we'll rotate them 90° and move them in the y axis minus half of the size so now if I connect everything if I stop debugging this these are these are the original points I'm moving them forward with this first transform moving them backwards with the second and the two different nodes are creating the two front and back sides combined with these two different notes I have the four sides of the floor to spawn the walls and the PS so let's stop debugging and now because everything is set with a static number here inside our nodes we work only for this particular size of elements and we don't want this we want our subgraph work for any building that we create so let's start populating these fields I just wanted to show you how this is working so you understand everything and are able to debug if there's any problem on your graph let's start by into our graph let's actually make this into a subgraph so select everything here right click and coaps into a subgraph let's save this subgraph here where the other graph that we are creating is made and call it PCG subgraph four or single four to be more precise with the naming so now our PCG graph only contains this single four subgraph and it's doing exactly the same thing as before let's double click into this single for subgraph or find it in your browser and open it from here we have the same thing here difference is that now I'm going to create some parameters here so click anywhere on this uh empty space so you don't have anything selected or click here onto the graph settings Note on top and into the parameter Fields create couple new parameters so I'll create I will believe six let's or seven I think we need seven for now so the first one will be the length of our building the second one will be the uh width of our building we need the height of our building then we'll have uh wall length then P length then we'll have the cink height and we can create one field for the cell size this will be com combining the length of our wall and P it will be easier to connect everything inside this way or we can just calculate it inside let's remove this cell size we'll use for now just this uh six parameters so the first three needs to be an integer so let's change the type for all of them from Flat to integer and the other three can be a fault value so let's save both of our graphs let's give our parameters a default value so the length of our building let's say it will be Four Walls by the length of the building the width will be three the height for now it will not do anything because we're doing a single four but let's say five the wall length will be 400 by default the P length will be 75 and the ceiling will be 400 these are the default values for the building that we are creating now they can be overwritten for different type of um meshes for other sets from Quick cell or or other meshes that you have for your buildings but I'll start with these default values that way we will be easier to debug everything when we have default values that match our element so the first thing that we can do is use this parameters when we are creating the point grid so the grid extends field you remember that I created it by multiplying the width in an integer value so I multiply three by this size so let's first create this cell size variable this will be our wall length so start typing wall and you will get this wall length variable it's currently set to 400 let's add it so drag out of it and type on add to create a mat operation addition so make sure here it said to add now right click anywhere and start typing pink pure it will give you the pure length variable so when we add this W length and this P length we are getting the cell size of our grid so this 475 we will get from the addition of our two elements that we set up by these parameters so the grid extent needs to be our width and our height multiplied by this cell size so the width we'll drag and do a multiply by this cell size and we'll copy this multiply and do it again for the height I'm sorry not for the height but for the length so type length and choose this get get length parameter so connect this and multiply it by the cell size and now drag out of one of these multiply nodes and make a vector the type of vector we need to change to regular Vector with three values the x value will be the multipli multiplication of the width and and the cell size and the Y value will be the multiplication of the length and the cell size value then for the Z we'll just get the ceiling height and set our Z value here now let's connect this to the grid extend and in this way we are making our grid generation based on the values that we set up in our parameters and not just uh statically set up every building the same size each time so now we have control over the size of the building that we create so if we debug now this bounce modifier you'll see that one of the sides is bigger than the other because we have the width of the building set to four and the length of the building set to three so now we have a different size for the two sides of our building so now let's stop debugging this and let's start making this transform points use the parameters that we just created and not to be set up statically like it is now so this 237 is actually the C set size divided by two so the cell size is this result here the wall length added to the P length let's copy this here let's divide the result of this by two so drag out of here right divide and for the second pin here right click somewhere and add parameter add attribute sorry and the attribute will give it a value of two so we'll divide by two and the result will make Vector like we did before so make Vector the vector will be Vector three values and now this Vector will connect to the first transform points offset minute offset Max you will see the offset minute Max is this value for half of the cell size well let's connect this here let's collapse this and for the second one we need the same Vector but this should be a 237 so when we divide this we need to multiply the result by minus one so let's copy this at attribute and type minus one so we have 275 Here and Now 237 sorry here and when we multiply it by - one we have negative value and we'll make another Vector which is with the negative value and connect it to the other transform points so now if I show you everything let's select this divide note click the a key then go here and select this subgraph when we select the subgraph to debug everything becomes disabled so it shows that there's some error and it's not working so actually here in the 5.4 version they changed this Behavior so this at attribute needs to be connected to some points and we don't have this so we need to create attribute instead so the value here is 0.5 actually two let's copy this and the value should be minus one okay so now everything is working fine let's select this divide node actually let's select this ad node so first when you select here the subgraph and you click the a key for this at note you'll see that it's calculating properly the W length and the pure length together to to 475 then we are dividing by two so let's change here the a key to the Divide not so 237 now this multiply is minus 237 this Vector has an x value of 237 and Y and Z to zero so we are mimicking the behavior that we had before X is 20 37 and the others are zero the second Vector is- 237 so the same thing here so now for the third and fourth transform points here you can see it's the same thing but the values are in the y axis so copy this make vector twice and for the first one connect the positive value to the Y and for the second the negative value to the Y let's move these things and now the transform points offset for the first one we'll have the positive values and for the next one the negative values the y direction and now if I debug all the difference notes I have the same result as before I have the four walls Points each in the direction that I want you cannot see the directions here because they are just Cubes but if I change the debug option here not to the cube but to the axis tripod you will see the arrows pointing let me just move this a little bit up we need to move our points up because they're currently below the four so for each of these transform points select all four of them or actually just here we have the offsets for all of them so let's use the ceiling height so ceiling height variable that we have let's divide it by two so copy this divide note in this value of two and let's connect this ceiling height to all of the Z values oops sorry okay now we have them on the floor so you will see that the rotation that we added to this uh uh transform points it's making sure that for each wall this red arrow is pointing in the outside Direction if we don't rotate the points for example here on the second one if we leave it at zero we'll have a problem where our walls here on the left and right they are each pointing to the right so when we create the walls the outside of the walls will be inside the building here so that's why we are rotating here 180° and these two transform points on the bottom we're rotating 90 and minus 90 to have the other two walls facing the same direction so now that we have all these uh points for the walls let's continue with making points for the corners for the corners of the building let's combine these first two walls so let's debu only these walls so let's do a transform points for this transform points this is creating this note that's converting to points the result of this difference so connect both of these first two differences to these two walls to this transform points note connect the bottom ones to another transform points and let's move these points with the half of the value of our cell size so because we are using this cell size in a lot of places we are calculating it here sorry we're calculating it yeah here so let's drag out of this at note and and start typing at named route and choose this at Route declaration note then right click and choose rename and write here cell size so now if we drag out of here we can always use this cell size like it's connected to this node here so here where when where we had this addition in our divide node here for them transform points we can just use this uh rear route node so right click and choose the cell size note and now where we need it here right click again choose this cell size and we need to divide this by two so divide make create attribute this attribute will be two we'll divide by two we'll make a vector the vector will be with three values and we'll connect it to our offset Min and Max or both of our transform points here and actually we'll connect it to the Y value not the X one so now we have half of the length for our cell size transform here for each wall so you'll see that if I this first transform points it's moving the points to the side and for each wall it's different side because they are rotated 180° and if I debug the other note you'll see that it's moving them again in the opposite directions so now I'll do an intersect between the moved points and the original points of the two differences nodes here so let's do an intersection let's debug this intersection and you'll see two points for the two corners that are created and of course we'll need another intersection where we'll intersect the result of this transform and this original points here so if I debug the other one we have the two other corners and if I debug both we have the four corners of the building if I show you the results that we have we have the two walls on one of the sides into this first pin the two walls for the other side in the other one the two corners in this first intersection and the two other Corners in the second intersection let's move the corners up now we'll create for the corners transform points we'll connect all of them these are all of our Corners here let's debug this these are our for four corners and we have a transform points to modify them and let's merge these points for all of the four walls and let's split from these merge points to create two transform points operations the first one will be for the pillars and the second one let's copy it it will be for our actual walls so let's stop debugging this let's start creating here the logic for the transform for the PS and the walls so as I showed you before when we create a wall let's go back to our walls when we add a wall in our level it's placed based on this pivot point and the points that we are generating we want the placement for the wall to be in the middle of the wall with the pillar next to it so what we need to do for these transform points is again calculate the transform that we want to apply with this offset values in order to have the wall placed over the point that we are using to generate it so let's use our wall length so right click and start typing wall and choose the wall length parameter let's multiply this or let's divide this by two so let me copy from somewhere okay this create attribute to so we are dividing this wall length by two and then let's add to our wall length the length of our Pure so start typing pure and add the pure length variable here so now we'll add the pure length to half of the wall length and we'll use this to make Vector attribute we actually connect it to the Y value because this is the side to side movement of our wall we'll change this to a vector with three values and we'll move in X with the amount that our Pure with as well because when we stack walls next to each other like on the corners we need to account for the p size to make a room for the P between the two walls so we'll add our Pure length here for the x value but we'll multiply it uh we'll divide it sorry by minus 2 so we'll have the negative value of half of our pillar width I'll show you what this is making to our points so let's connect this into our offset minant Max for the pures and then let's spawn static mesh spawner let's choose the mesh entries let's add another one let's choose the descriptor and here into the static mesh let's choose our pillar so drag this pillar into our static mesh field is the corner one so this one let's drag it into our static mesh let's delete the walls that I used to show you so the pill are actually not facing the right way so these transform points we'll also use to rotate them minus 90° okay so now our purs are placed between each wall and here when I'm dividing this pure length by two if I divide it by one so it's actually let me Spawn the wall and I'll show you let's put minus two now let's do the same transform for our walls so we'll use this pure length and this wall length so divided by two so let me rearrange some things so let's make another Vector will be a type three Vector I'll connect this here so for the walls we are moving them half of the wall length on the side and then half of the pure length to inside of the building so let's connect this here into this transform points ofet Min and Max let's copy the static mesh spawner and let's spawn not the P but the wall instead I need to rotate the wall so minus 90° for the wall as well okay now I have the wall and the PS actually because you can see on the corners they're overlapping too much I don't need to move them to the inside I'll change this to a positive two so now we we just get the half of the P length and moving our wall outwards with half of the length so if I mark this make Vector click the a key and select the subgraph here you'll see in the x axis we are moving it with half of the P length to the outside so we have a place here to place our corner and the only problem is that we are spawning a p in each Corner that we don't need so for our pillers here before we spawn them we need to at a difference note and we'll use this pillar as a source and the corners that we got here so connect these Corners to this difference note disconnect the spawning of the PS and connect it again so now should be able to remove the corner elements here so it's not working because we need to edit the bounce before we do this so bounce modifier our Corner points are currently not big enough to be able to do this uh operation or maybe we just change the operation to Binary so it will be enough okay so we get this result with just changing the type of the density function to Binary otherwise we could make the bounce bigger and it would work but we can change this to Binary and it will work better now without changing the bounds to our Corners so let's start stop debugging the corners and now we are placing all the peers and the walls we are just need to place the corners so after this transform points let's copy this static mesh spaer let's choose this corner pillar and add it to the mesh entries and let's connect this transform points here so the problem is it's not spawning directly in the corner we need to transform it byus 75 / 2 okay and in the other direction we need 70 5 / 2 I believe yeah so you can see these are the negative half of the P width and the positive half of the P width so we have this the pure divided by two so let's copy this let's paste it here let's copy it again and and paste it and get the negative result for one of them the positive for the other the negative should be in the X Vector so make a vector change it to type of three the positive should be in the Y and now connect it to the offset minute Max and now we are spawning the corner we are spawning here the pillers and we are spawning the walls if you mark any note and click the E key it will enable or disable e for enable so you can easily test what each spawn mesh note is doing by marking it and clicking e to disable it so we are placing each wall each P and Each corner with these notes here and the size of the building is directed by the variables for our width length and the size of our wo and pure if I save this and if I go back to the original PCG graph which contains this sub graph currently only this subgraph so now if I open the blueprint where we created this variables width and length and height I go to the original PCG graph get actor property and for the actor property name add the name from your blueprint let's get the width the length the height the wall length let's copy them to not do a mistake now the pure height pure length sorry we are not using the corner length we are using the ceiling height so let's get the ceiling height as well so now we have all these properties here into our graph let's open this subgraph and let's starting connecting this is the width you can see here in the orange header it says what property you are using so this should be the width this should be the length this is the height this is the wall length this is the pure length and this is the ceiling height so let's save this let's compile and save this graph again make sure that you have default values set up here for all of these variables this is three for the length and height of our building the wall length is 400 pure length 75 and ceiling height is 400 so now I delete this blueprint when you put the blueprint in your level it will generate based on these values and if you change them it will change the size of your building currently if I set the size to two it's generating more walls so let's check what we are doing inside our single floor so we are getting the length we are multiplying by this cell size we need to get half of this value so let's get half of this Vector so multiply this and add attribute not add but create attribute now let's do a 0. five multiply by 0.5 or you could do divide by two so this will Connect into our grid extend value let's save this and now when we're in our level we can control the length okay now I have properly three units of length the width I have properly formed units so now you can place the blueprint and generate single floor I believe that we are heading to over an hour currently so I'll end this tutorial for now with the generation of a single floor and in the next tutorial I'll show you how you can use this floor to generate first maybe we'll start with the variation of the elements on the first Flor so we can add doors or different type of uh walls with garage door something like this and then we can proceed with creating the other walls the other Force sorry and at the end we'll generate the roof and add the decals to make the building look more natural and after this we can start modifying this uh blueprint to work with other assets like I showed you I have the different nail Baro building connected and you can generate different buildings with the same blueprint so for now that will be everything and if you have questions or some problems please write in the comments and I'll see you in the next video bye [Music] n [Music]
Info
Channel: DK 3D
Views: 5,960
Rating: undefined out of 5
Keywords:
Id: Wl5ft5WIro0
Channel Id: undefined
Length: 61min 32sec (3692 seconds)
Published: Sat May 11 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.