Create Entire Cities Automatically With PCG Splines! Procedural Content Generation in Unreal Engine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello in this video I'm going to be showing you how I made this medieval town in just a few minutes using splines with the procedural content generation framework inside of Unreal Engine I'm going to be showing you how to use a spline Circle to define the shape of your town how to use a spline road to cut through that town and then how to spawn a road geometry along that spline in order to fill out the effect and if you're new to PCG and you want more of a beginner's guide I will link that video below this so let's get into it so here's the town we're going to be building I'm just going to come over here to the spline actors and the PCG actors and go ahead and delete them and you'll notice I have already set up a PCG volume inside of this level to spawn the forest that's going to be around this medieval town but if you'd like tutorials on how to do that I will link that as well below this video so what we need to do to make a Town spawned inside of this Forest is first to create a spline shape that will cut out the existing PCG volume that I've already set up here so we need to make sure sure there's one plugin enabled here and that is under edit and plugins we're going to type in modeling and you want to make sure you have modeling tools editor mode checked on and if it prompts you to restart the engine go ahead and do that now I'm going to come up here to the drop down in the top left corner and I'm going to choose modeling here this is going to open some modeling tools for me on the left side here and this is a much easier way to make a spline then to make a blueprint with a spline inside of it which some of you may be familiar with if you've made splines before this is a much easier way and gets us the result we want much quicker so I'm going to go ahead and come to the draw spline tool here and you can find that if you're not in it in the create button on the top left corner here so click on that click on draw spline and one thing I want to check here is that I uncheck world I really just want to Draw It On The Ground plane I don't want the spline to like draw onto trees up and down so I'm going to uncheck world but if you need a draw spline on other objects make sure that's checked on so then I'm just going to go ahead and click around in a circle however big I want my town to be here and in the top left corner here where it says Loop I'm going to go and check that so it closes the loop for me and I'm going go ahead and hit accept right here so now I have a spline for the shape of my town this can always be changed later as well if you want to edit it I just come out of the modeling mode and I can choose one of these points and move them around so the way that we're going to tell the PCT volume to use this spline and not other splines we're making in our level like the one we're going to make for the road is to add a tag to it with that spline actor selected I'm going to come over here and on the right side here I'm just going to go ahead and search tag to save us some time in the search bar here and under the actor tag section here I'm going to hit the plus button to add a new tag to this object and we're just going to call it town and then outside and pay attention to what you name it here cuz you'll need to remember it and type it into the PCG volume later so I'm going to go ahead and hit enter I come over here to my PCG volume here for the forest uh I click clear the tag section here that I added and I scroll down to the PGG component open the PCG and graph instances and then instance this is a PCD graph that's connected to the volume here so I'll double click on that to open it okay so this is what I have set up for the forest I have just a landscape surface sampler coming into a transform points to give the trees some random rotation and then I have some density filters to adjust how many points are on the surface and then I have a static mesh spawner for trees rocks and things like that okay super simple so what I need to do is cut out these points in this area here right before they're used to spawn so once I've done all the adjustments to those points that I want we're going to be creating a difference node so I'm going to draw off here and type in difference and I'll hold alt and click on this input here to disconnect it and reconnect it to the output and you want to make sure that the source here which is the point spawning those trees is plugged into source and then the differences section here that's where we'll plug in the data from our spline so in the difference node I need to change the density function here to Binary what this is doing is it's basically telling this node that when we give it the points that the spline has created inside of it which we're going to set up in a second to either choose one or the other so basically to completely remove all the points that overlap with the points from the spline so now we're going to right click in the empty space down here and I'm going to type in spline I'm going to choose get spline data first because we need to get this spline into the PCG graph and with that node selected I'm going to come over to the actor filter drop it down and choose all World actors so it's going to sample all the splines I have in my scene but I'm going to choose by tag here so it's going to choose the spline with the correct tag which if you'll remember we made as town outside and if that tag exists in the world you'll see the error on that spline data go away so it's got that's a good thing that means it's gotten the data from our spline now I'm going going to drag off of the get spline data here and we need to make a sampler just the same way we would sample a landscape so I'm going to type in spline again to get spline related stuff and we're going to choose a spline sampler here in the spline sampler there's a few different ways we could sample this spline and later on we'll use a different one but for this we want the inside of the spline so if I come up to the dimensions and instead of on spline I switch it to Interior it's going to get all the points inside that shape that closed shape that we made so let's actually take a look and make sure this is working so I'm going to come over and disconnect my mesh spawning so that we can actually see what the graph is doing then I'll contract this down so this is the shape of our town here and in the spline sampler I'm going to go ahead and press D to debug and we have one problem which is that this is only being sampled inside the bounds of our PCG volume which I actually turned off for the trees so it would fold the entire landscape so we actually have to to turn that off for the spine sampler as well and it's not actually super important to have only things spawn inside that volume because we're actually using the spline itself to tell us where the points are so we don't actually need that bounding shape of the volume so I'm going to come over to the spline sampler and choose Unbound here once we do that it's going to show you that it's spawned all these points all over the place so now we can come over to the differences node and let's take a look at what the points that we're using to spawn the trees look like so UND debug the spine sniper and debug the transform point and these are all the points I'm using for the trees and rocks so if we plug the spine sampler into the differences node here and we debug that you can see that the spline sampler is using the points from the spline data node to cut out those tree points so now if we plug it back into our mesh spawner section we can see we have successfully created an empty clearing all right so let's make a new pcga volume for or the town itself I'm going to close this for now right click in my content browser and come to PCG and choose PCG graph as I mentioned in other tutorials if you don't have the PCG option in your content browser it means you need to enable the plugin procedural content generation framework plug-in so I'm going to call this new PCG graph PCG town and I will drag it in to the environments I'll hit generate on the right side here and then I'll double click on it to open okay so we're going to come into the empty space here right click and type in and get the get spline data node here like we used before and we'll come over here to the action filter on the right side and choose all World actors and again under the buy Tag section we will type in town outside there we go so we're going to drag off of the out again here type in spline and get the spline sampler same as before this time let's go ahead and hit D to debug this particular node so we can see what we're working with and same as before we need to come over to this blind sampler and choose under Dimension where it says on spline you want to switch it over to on interior and scroll down again and choose Unbound or you could scale the PCG volume up far enough so that it would cover the whole spline shape it's up to you okay so it's pure white here and that's because all of the individual points are too big so I need to actually mess with those Point sizes so that it doesn't spawn too many buildings when I actually connect up the geometry spawner to it so we can start modifying these options here right now the interior sample spacing is 100 that means there's 100 units in between each sample if I increase that number to say something like 500 we can see it makes the dots smaller because it's giving a 500 space in between them I'm going to go ahead and actually increase this to 2,000 and you'll notice by default these points are getting spawned in a grid which is what we want for a town if you were to sample the landscape not using this method you would get points in a more random layout or random format and in this case we're getting a grid by default which is good one thing I do want to modify here is the bounds of each point since they're kind of small if I were to run a road through it which we're going to do in a in a second they would not actually probably overlap any of the points and therefore not cut them out they need to be roughly the size and shape of the buildings that we're about to add later so I'm going to go ahead and drag off of the out here and type in bounds and choose bounds modifier and we'll just up the bounds m Max to 10 on all of these once we've done that we can go ahead and debug that node and we can see these are much larger cubes which will work a lot better when we're cutting it out with the road okay now it's time to add our static mesh spawner to put our buildings in I'll drag off of the bounce modifier here type in static mesh spawner okay so we have the static mesh spawner I'll come over here to the mesh entries and expand that now I have downloaded a medieval buildings pack which I will link below this video if you're interested in using those as well but it contains all of these buildings here so I have a bunch of different buildings that I'm going to be adding to my mesh spawner so I'll just add one to show you how to do it which is to expand the mesh entries under the static mesh instance here and drag in a building of your choice then contract it hit the plus button again add another one open the descriptor drag in another building and we can see that we're already starting to populate our little village here now this is actually going to really look the best if you have a lot of different building options and I actually do I have around 22 of these buildings so I'm going to go ahead and plug all of those into this mesh spawner all right now they're all plugged in and we can see we already have a village that's looking pretty good here if you're not really happy with sort of the placement of the buildings or it doesn't quite look random enough you can come over here to the static mesh spawner and you can adjust the seed which is going to choose a just a random different selection of buildings here or if you're still not getting enough random something I have noticed helps a little bit is to add an additional node which I'll grab by typing in noise and I'll choose attribute noise and I'll plug that in in between and in the attribute noise under the input source I'm going to click on the little plus button here and choose seed and by default it's going to have only one building and then as I increase this noise Max here it's going to just creep increasing the randomness till I get something that I like that looks pretty good and if we have our buildings pointing in the wrong direction we you can always modify that as well by adding a transform points note here in between coming over here to the rotation Min and Max and adding a rotation in Z maybe 9° and that will rotate all of the buildings 90° now this really works best if you've modeled or at least rotated your building assets that you're starting with to be all facing the correct direction if they're all have the front of the building faced in different positions they're not going to quite look that well here and instead of adding like a lot of logic in to make sure they're all pointing the same direction it's just simpler to make sure each of your assets is you know efficiently pointing in the direction that you want them to point you could also use this rotation to add like a slight bit of Randomness maybe not too much but maybe between -5 and 5 that just rotates the building ever so slightly depends how gridlike you want them to look so now we're ready to add our road and the road is going to be another spline that we add on top here and it's going to cut through the points that we've already laid out for the town so come back over here to the mod modeling drop down and choose my draw spline option here I'm just going to have it go straight through the middle of my town I'll go ahead and hit enter switch back to selection mode and our second spline actor here we need to add a tag as well too so I'm going to come over here and insert type in tag for the asset and choose a little plus button here and type in Road shape or whatever you want to add next we'll come back into our graph here we'll right click and get spline data again and and this time we'll choose all World actors and the tag will be Road shape then we'll drag off of that sample it and I'm going to actually disconnect the houses here so that I can actually see the points that this new road is making so hold down alt and disconnect the static meshes and we'll go ahead and hit D to look at the spline sampler and I'm going to come over here to the mode here where it says subdivision and switch it to distance this is going to lay the points out along the curve more evenly we will keep it as on spline here in contrast to what we did for the town earlier and we'll drag off of here and make a bounds modifier we'll debug that and let's expand those points because right now there are actually points being simulated but they're too tiny to see so we'll just come over to the bounds Min and Max and let's in the Y AIS increase it to 500 here we can see the points have expanded the width of about the shape of the road that we want however they're only getting simulated again within the volume the PCD shape so probably we should have just made it bigger but at this point I'm committed to using the Unbound option here so I'll come over to the spinee sampler and check on Unbound and now you can see the points are being simulated all along this line okay so now we have our road and we have the points of the town so we need to make a difference node in between here so drag off of the transform points that we're using to simulate the buildings make a difference node and the difference is going to plug into those points from the road let's go ahead and look at what that looks like and you can see the road is cutting right through the building here however nothing is happening as because in the difference Zone we need to come back over here if you remember earlier we need to switch the density function to Binary and then it will cut out the buildings that overlap with those points now we can plug it back into our static mesh spawner and we have a road that will dynamically cut through our town and to make this road look a little bit better I'm going to add a mesh to be simulated and spawned along it and repeated to make kind of a muddy path so I'll drag off of the actual Road points here and make a transform points node so I know I will need it to modify the mesh then I'll drag off of that and type in static mesh spawner and I will be adding the forest ground mesh which you can find in the quickel bridge so add a mesh entry here drag that in and we can see it is a bit too small so we'll come over to the transform points and increase the scale Min and Max by five We'll add a random rotation as well in the rotation Max section here under the Z axis We'll add a 360 so it'll rotate from 0 to 360 and to push it down into the ground ever so slightly to help it blend a little bit better I'll come over to the offset mid and Max and add in a negative one to the Z axis and if I feel like there are maybe too many meshes getting spawned in a line here I can just come over to the spline sampler here and this distance increment is very similar to the one we used for the placement of the buildings so I can come over here and increase this to 500 so create fewer points um along the spine there you have have it that's how you make a medieval town in just a few minutes this can go very complicated very quickly if you'd like to add additional Logic for how the buildings are placed or how the road maybe spawns other meshes I could imagine you having Street lamps that are spawned along the outside of the spline on either side but the starting point is really to get that spline shape in the overall shape of the town and then the road spline that goes through it let me know in the comments what you end up actually using this effect for I'm very curious to see how you all will apply it in different types of projects if you found this video helpful shoot me a thumbs up so I know to make more on this type of thing and if there you're out there and you're a beginner and you're just confused and you want more of an onramp up to these more complicated effects and specifically making animations or films with Unreal Engine I have a free training which you can take a look at which is linked below this video as well as a bunch more videos on ptg specifically right here so I will see you in the next one
Info
Channel: Aziel Arts
Views: 31,246
Rating: undefined out of 5
Keywords:
Id: STqt92VF3KM
Channel Id: undefined
Length: 16min 56sec (1016 seconds)
Published: Mon Oct 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.