Quickly and Easily Assemble Modular Buildings With PCG

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I'll be showing you guys how to take these modular building pieces and then fully randomize the buildings as well as be able to really quickly attach a different piece to it and have it automatically cut out anything that it is using and when you're done all you need to do is come here and clear it and now you have a full solidified building you can place wherever you want so let's get to it to get started let's go ahead and enable our plugins so we're going to search for procedural and we want to turn on procedural cont generation framework BCG and restart your engine if you you haven't already after that we're going to need two things of course our PCG graph and I'm just going to call it PCG modular building and we're going to need a blueprint that houses all our information so I'm going to add a blueprint class it's going to be an actor and this is going to be a BP modular building let's open up our blueprint that we just created and here all we're going to do is add our PCG component and the PCG graph that we created click it inside and we're pretty much done with the setup we don't need anything else in here but we are going to need some variables exposed and some settings so let's go ahead and create them now so we don't have to keep going back and forth all the time starting with static mesh we're going to create a static mesh variable and the type is going to be of static mesh and it's just going to be an object reference and it is going to be exposed then we're going to need three floats so I'm going to select float here and I'm going to click plus two more times so I get two more floats and one of them is going to be an integer so for the three floats that we're going to need we're going need to have the chance of doors chance of bottom windows and chance of upper windows and the final thing that is going to be an integer is just going to be our seed and we want all of these exposed so this way when we create the buildings we have the option to actually modify how many windows we get and how many doors now this is not a set number but just a chance of spawning but there are ways of of course doing specific numbers as well but that's involving custom nodes and that's just a little bit outside the scope for this video and then the seed will allow us to just randomize all of our stuff with all the variables in here the one thing we need to do is actually modify the static mesh in terms of how the PCG is going to read it because PCG grab can't read the static mesh directly what they can do is read the string and this is specifically for using them for the static mesh spawners and not as an input for something else so in our construction script we're going to grab our PCG and get the graph instance and here we're going to search for set string parameter now we haven't created this yet but we will and for this this is going to be our static mesh and the value we need to do is get it from our static M so from here I'm going to drag this out and then we need to get object object path string Under utilities this one right here go ahead and select it and we can pipe this right into its value with that in the out of the way let's go ahead and just copy this and create the parameter in the PCG graph so here under graph settings we'll go ahead and create a new parameter now if you don't have this you might be in 5.2 this only available in 5.3 forward so I'm going to rename this to the static mesh that we had and I'm going to change the type to be a string and that's all we need to do on this one so now let's go ahead and start with our PCG graph let's get actor data and for for actor data we want a single point on self and then we want to add attribute now the attribute Target is going to be what is going to be called so I'm going to call it static mesh and then we can go right here and get static mesh and this is our string and I can just plug this in here and it'll go ahead and convert it all these settings it'll convert accordingly then from here go ahead and drag out a static mesh spawner and we need to change the mesh selector type from its default to selector by attribute and then under attribute name you want to put in static mesh which is what we called it here so now if we go into our actual level our mesh is currently empty so now I'm going to grab this and I'm going plug this in and you can see it populates if it doesn't immediately populate you might just need to move this and offset it so it automatically regenerates but you can see we now have this populating on the different buildings here like so so this is an easy way of storing the static mesh into the static mesh spawners but now we want to populate in the windows and things of that nature now the easiest way I think to do this is to use sockets all static meshes can have sockets on them and you can place them wherever you want and we can use the information from the sockets to spawn anything we want like the doors windows Etc so I'm going to go ahead and open this static mesh and just to the right of the details you have the socket manager you can go ahead and open this if you don't see it under window make sure socket manager is turned on and we just need to add some sockets in here so let's start with a simple door when you add it you'll see you get a little icon here you can just move this around to wherever you want and the nice thing is down here under advance you have the preview static mesh and a tag so the tag we're going to set is door CU these are going to be our doors and we can go ahead and just add a preview mesh here so I'm going to select one of these doors and then I'm just going to populate in here so I have a nice preview of it so I can get the position exactly where I want it so I can move it forward back according to the meshes that we're going to be using and then I'm going to duplicate this door a few times I'm going to take this and maybe put a door here put a door on this side and just go around and place the doors on all the sides you might want a door and all positions where you might want a door so there we go I have placed a door location basically everywhere where I would like to have a door now to make it easier so I don't have this in the way I'm going to go ahead and just select these and clear out preview mesh from these we don't need it anymore and we're going to do the same thing for the windows so I'll make a new socket and this is going to be bottom Windows the tag will be bottom window and the preview mesh again I can grab one of these guys slot it in and now I can move it forward you can see we now have our window now this window in our case is pretty small I would like to have it to be a bigger window honestly I'm actually going to change the relative size here to 1.5 instead of 1 so they're just a little bit bigger now you can keep it to be 1.0 and you can modify this in the PCG graph itself it's Al all up to you it depends on what kind of meshes you have if they're all consistently small Windows you want bigger windows or vice versa you can just adjust it on the socket and it'll propagate to everything so I'll go ahead and take this and I'm going to duplicate it around and place it in all of our areas where I potentially would like a window and there we go we now have our window positions on this building this is everywhere where we could potentially have a window and now we want to do the upper window these are going to be more of the balcony style so I'll go ahead and add new socket and this is going to be our upper window and just like before I'm going to grab one of these for a reference plug it in and now I can get it into position where I think it would look good and the same as the bottom ones we'll go ahead and just duplicate it around but we want to make sure it has a tag and we'll call it upper window duplicate it and position it and there we go now I've hidden the preview of the doors but that's just because we were placing the windows and they could potentially be in the same location so again in way you can leave these previews there they're just that they're previews and the final thing I'm going to add are chimneys so I'll add a socket for chimney and the tag will just be chimney I'll grab one of the chimneys and use it as our preview and now I can go ahead and just position this accordingly and I'll just set up two locations on the chimney so maybe one here and one over here so now all the sockets for this mesh are done and we can get started with the PCG graph to actually start utilizing it so now to start utilizing the points I'm just going to select this and I'm going to comment it out to be our main building spawner just keep it a little bit organized and now we need to actually spawn the points now the easiest way to get it isn't by right click and say searching sockets cuz that doesn't actually work is to grab this execute blueprint drag it in and under blueprint element type search socket you can get mesh sockets to points now this requires a static mesh input but luckily we do have a static mesh attribute that we can pipe in here so I'm going to right click and get actor property and in our property name I'm going to type in static mesh cuz as you recall we that is the variable name that we have placed in here I'm going to take this out and plug this into static mesh now quick note I have had it where this variable this static mesh says oh it is actually not valid it doesn't understand it and it airs out with a big red thing underneath if that does happen to you just restart unreal and it's going to be fine it's a bug that I just found recently but it's good to know about so with this go and close this and the tag that we want to actually use is going to be door cuz that is the tag that we actually used here you can copy paste it depending on how simp the tag is it might be easier and then from here we want to do a copy points CU we want to copy these points onto the original mesh now I'm going to take this actor data I'm just going to duplicate it down here and pipe that into the Target and if I was to sample this you wouldn't actually see anything even though I'm moving this around or anything for some reason this copy points does not allow you to sample but if I just go static mes spawner here and I'm just going to add something to this just under the script here I'm just going to select this Cube I'm going to place it in here you will see that it is actually spawning them so for some reason the copy points node you can't sample it for actual points but as you see it does work and we now have a spot here where we have placed the doors fantastic so now instead of this let's go ahead and populate all the static meshes in here all the door variations we have so in here I'm going to select all these four doors and I'm going to make four indexes for them there you go all four have been piped in and if I take a look here we now have one of four doors on every single one of these which is fantastic but we have way too many doors so for this I'm going to detach this and we're going to pull out of copy points and we're going to search for noise and we want attribute noise and then we want to get a density filter now I'll go aead and plug this into our stic M spawner for density filter I'll make the lower bound to be zero and the upper bound we've actually created the variable for it chance of doors so we'll go ahead and take this and I'm going to copy the name so I don't misspell it and then here I'll open the density filter right click get active property and the property name is going to be our chance of doors and that is going to go into upper bound collapse this and now if we take a look at this we now have far fewer doors there's a door there and see no other door is actually available if I change the chance of doors to let's say .5 we have more doors 3 but as you see it is changing the amount of doors but it's not changing the type of door or anything of that nature and that's where this seat comes in so for our attribute noise we actually want to expose our seed so I'll open this up and I'll duplicate this get actor property and I'll call the property name seed which is our name of the seed and I'll just plug that into our seed very simple here but we also want to actually randomize the windows that appear there so we're also going to put the seed into here into the static mesh spawner so now if I change the seed to let's say 10 you can see the door has changed 15 20 I can just drag this around and I will get different doors and different amount of doors based on the spawn chance so if I change this to 0.5 you can see we have more doors and they're going to be different every single time now you might want to keep them all within a certain theme of course for your setup this is just to show you how you can randomize them very easily you can have specific sockets for stone doors for wood doors Etc that's up to you to figure out how you want your thing to look in our case I'm just making all the doors be a possibility for these buildings if you guys are enjoying the tutorial so far I would love to hit the like button and while you're down there consider subscribing for more awesome tutorials like this but now let's go ahead and spawn the windows for the windows we can pretty much take everything here and just duplicate it down below the main things we need to change are the mesh socket to point tag as you recall for bottom window this is our tag so I'm just go ahead and copy it and paste it into our new tag so now it's only going to do the bottom windows and we need to change the static mesh spawner to have Windows instead of doors now as you see we have round windows and Square Windows and I would like it to randomly pick between either doing round windows or Square Windows but I don't want to ever match both together so let me show you how that can be done for this first static MH spawner I'll just populate it with these round windows a quick note I've noticed that when you duplicate the get actor property it sometimes stops being a regular G actor property and has this in node it's as simple as deleting it and then doing another get actor property and just piping in the information one more time I'm not sure why it happens but it seems to be a little bit buggy when duplicating now that this is piped in with the round ones I'll duplicate it and for this one I'm going to just populate it with the square ones and I'll go ahead and pipe in the seed in here the same as before now we want to change what it spawns right so the easiest way to do that is with a simple bll the first thing I'm going to do is actually rename this to spawn bottom windows and then I'm going to add a branch node now from this density filter it's going to go into the branch and then output a is going to go here and output B is going to go here now now if I expand this Branch note I have output to be as an option so what we're going to do is go into graph settings and we're going to add a new parameter here and it's going to be type bu and we're going to rename this to random window shape I'm going to copy that immediately so I have access to it and here I can go get random window shape and plug that into output B and now in our blueprint we can get our graph instance and do set bull parameter plug in our node plug in our graph instance and then from our bull we just say random Bull and now I'll just pick randomly true or false and the name going to paste in random window shape so now if we come here you can see we now have it randomly selecting and sometimes we have Square Windows sometimes we get around windows but we have the problem of them overlapping so let's go ahead and remove the Windows where there are doors in our PCG graph right before this Branch I'm going to add ourselves a difference node now the actual density filter will go into Source the output will go into the in of the branch and the difference is going to cut out these doors so from this spawn doors note out of the static mesh spawner we're going to use that in the difference but then on the difference note make sure instead of density function minimum you want to set it to Binary so that way just it's onoff cutout but now if I come here and I just change the seed you will see it will still occasionally spawn the windows but they will never overlap the doors it'll be right next to them because of our placement of our Windows you can see we now have a window in between the two doors but they will never be on top of it that's fantastic so now we need to do the upper level and the chimney as you see it is quite simple we can just take the spawn doors we can just duplicate it down here come here and we want the upper Windows now so let's take this TAG Upper window copy it in mesh sockets to points put in our new setup and I can rename this to Upper windows and of course for the static mesh spawner I got to go in and replace them with these there we go I populated all four of these into here and already you can see it is spawning all of them right there and if I change the seed of course will get different amounts and different types of them and they're always going to be in the correct location and one thing I actually missed is on these bottom windows we still have have a chance of doors here and for this we still have chance of doors as well so we want to come here and just copy chance of bottom windows and chance of upper windows and place them into our density filter for instead of chance of doors for both of these go ahead and replace those and that should be it now we still need to do the chimneys above so I'll take this spawn upper Windows duplicate it down and this is going to be our chimneys and of course we need to change the m sucket points to chimneys and in our case we don't actually have a property that we did chance over for chimneys and this isn't intentional on my part this is just to show you that you don't actually need it if you want to just have a random chance in general I just set this to be0 25 and I just have chimneys being a 25% chance consistently of spawning and of course for the STM spawner I'll go ahead and replace all of these with the chimneys and here's our full setup that I can just randomize and get random buildings with different kinds of chimneys occasionally sometimes you'll have both of them sometimes you won't so it's nicely procedural in the aspect now let's say we want to add the attachments let's say I want this guy and we want to attach it here and plug it in well I don't want to spawn the window here then I also want all of these pieces to have all the same ones so what you need to do is for every piece that you want this kind of setup on you'd open the static mesh and add the sockets to it accordingly of where you want things to spawn and that's what I did on these as you can see I've added in some sockets this is a different shape this is more of a T intersection as well as adding it on this guy here and here you just go in and add the sockets of where you want these points to be as always the full project is going to be available on my patreon and thank you so much to my patreon for supporting what I do it really means a lot and if you have any questions or just like to join the community the link to the Discord is down below come join us say hi and again thank you so much to the patrons and let's get back to it after that you can just take your piece and you can make a duplicate of it and then just swap out your static mesh is going to place the windows and doors in the same setup you had before and you can change it for this piece but as you see here we do have an intersection problem where I don't want things to actually spawn when they intersect so let's fix that next now we need the bounds of the actual building but we don't actually want the building in the end so there's a way of doing it because if we were to actually sample this actor data if I debug it you will see our point is just this because it doesn't have all the information of this full building so what we're actually going to do is we're going toe open our actual blueprint and we're going to add a static mesh in here and you may be wondering why we're adding the building in here when we're already doing the PCG graph and that's because when we actually finalize this building it won't actually be part of the final piece this piece will will just be left alone what I mean is this I take the static mesh I can drag it out and I can do a set static mesh and we already have our static mesh in here so we can just drag it in here but we want to change the visibility on this to be hidden we change the visible off and now if I come here and I sample this get actra data you can see it is actually getting the full bounds of that object because it understands the bounds of that static mesh we're not actually previewing that static mesh it is only previewing this one if I disconnect this you can see it goes away we'll go ahead and reconnect it but now we can use this data to call out everything else so all we to do is get this get actor data we duplicate it down here and instead of self we're going to do all World actors and by tag so we need to add a tag to our blueprint so in our blueprint self search for tag and we want to give it a tag now let's call this modular building and I'll copy it and now in our get actor data we'll put in our actor selection tag now we want to select multiple and we want to ignore self and children otherwise it'll cut out itself from itself then right before the static mesh spawners we add a difference node and we're going to cut out this setup and then we'll plug this in here and we're going to need this everywhere so I'm going to take this and I'm going to duplicate it and we're going to just attach it pretty much in all the locations between every single static mesh spawn there we go so it's plugged into the difference node now for these differences make sure they're all set to Binary because we only want it to be an onoff so I'll just control select all of these set them to Binary and we're all set there so now as you see there's no window here if I move this out of the way we have Windows as soon as I bring it a little bit too close there you'll see it disappear appears now it still spawns the doors and windows on this piece and it still spawns them on this piece so I take here and I change the seed it will still spawn all of them it just won't spawn them in these locations but now as to the question of well now that we have this why did I put the static mesh in there if we're just using it with BCG anyway if I come here and let's say I'm happy with this building this is the setup I want I want to lock it in all I have to do is come here to PCG and click clear PCG link and now if I click on here I have this full graph with all the instances that we've created and I can just drag it away but here's a note these are all the instances of it this static mesh is from our PCG graph it is not from this from the original graph and I can show that by going here and changing that the visibility on the static mesh to be visible compiling and now if I do the same thing with this one let's say go down here and click clear and I I select it now you will see I'm selecting the static mesh of the original PCG graph so if I click the windows and I drag it away there's the stamp with our building but that original static mesh doesn't come with it and of course I can regenerate it now again but the main thing is you don't worry about that static mesh it is there purely for your reference the reason we are spawning in in the PCG graph is because now when we create the stamp it comes with it of course we want to have visibility off because we don't actually care about that piece again now that these are just regular blueprints with instance pieces we can just place them and rotate them and do whatever we want now effectively we can just create really quick buildings using the setup just attach them can make another copy here grab let's say this piece and we can just extend all of these buildings and any way we want and they also follow the scaling so if I scale this up everything scales accordingly as you see here in my case I should have probably moved this window a little bit out but you can see everything is adjusting accordingly I can just embed this a little bit further in if I wanted to and you see where they're overlapping it no longer is spawning any of the extra stuff so with this you can go ahead and create any kind of shape building that you want it'll automatically have the doors and windows in positions that you would like them to have and with the variation that you want them to have so instead of manually dragging out a building and then a building and then placing a door here placing a door here right this you have a lot of control over this but you're going to want them within a certain style anyway and this method by just putting into a blueprint with some PCG and some prep with the sockets will allow you to really quickly create a big cities modularity now if creating buildings yourself is more of your style like creating the interiors and exteriors well check out this video here where I start my full building PCG series
Info
Channel: Procedural Minds
Views: 2,551
Rating: undefined out of 5
Keywords:
Id: 0XoNFwICbyg
Channel Id: undefined
Length: 20min 26sec (1226 seconds)
Published: Sun Mar 31 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.