UE5 | Procedural Suburban City Using PCG | Tutorial | Part 1 | Unreal Engine 5.2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to Maddie's hub uh this is going to be my first ever unreal tutorial few days back I uploaded a short clip of a PCG procedural content generation graph that generates a whole Suburban City within a few clicks so this video is going to be about how I created that please let me know down in the comments any suggestions you may have for me at the end of the video uh I will not be going through the basics of PCG because there are several good tutorials on YouTube that cover PCG extensively I would personally suggest tutorials by free time coder and Adrian Logan as they explain everything step by step and in a very well structured way I will put the links down in the description now what I understand about PCG is that there are multiple ways of achieving the same thing now even though I will be showing you one of many ways you can always explore a different way to do it and that is the most fun part of using PCGS so let's get started firstly we'll turn the PCG plugin on let's go to edit plugins search for procedural content generation framework uh let's click on it and restart the editor I have already done that so let's create a new level I'll delete the floor and use the landscape instead so let's create a landscape 63 by 63 is good enough so this is the landscape on which we'll be creating our Suburban City let's bring it down to 0 in z let's give it some material I have few good materials from Mega scans here this massive forest floor is good so it's assign it and we will not be creating just a single PCG graph instead we will make one main PCG graph and a few sub graphs for the separate elements like trees and Roads now why we are creating these uh separately it's because it makes our main graphs much more cleaner easier to read I'll create two folders one for blueprints and one for PCG graphs let's save this level call it map underscore tutorial I'll create my first BCG graph as the main one so PCG underscore I mean let's create another one PCG underscore trees we'll drop this main graph into the level and bring it to the origin and let's scale it up around to the size of the landscape so let's scale it up to 250. and that completely covers our landscape this yellow box that you see is actually the volume within which the PCG will work let's open up this PCG trees now you can see uh we it requires an input and an output so the we know that the input is going to be a landscape so we'll use a surface sampler node now what this node does is it will take the landscape input and it will create some random points all around this landscape let's grab the output of this node into our main one so just drag and drop this subgraph let's get rid of this output for now now in this PCG main we know that this main graph is in the level so if we give it this landscape height input that landscape is going to be this one which is in the scene if I go back to my PCG trees and press D on the surface sampler node you can see these are the points that have been created they are all of uh different colors because there is an attribute called density with which is automatically attached to all the points and its value ranges between 0 to 1 and we are visualizing that in the form of color between black and white now add right now the points are too many so let's decrease the number using points per square meter parameter to put a value of 0.005 and let's keep the looseness 0.5 so that they are more evenly scattered now let's spawn some trees on these points so we'll go into the main graph and use a node called static mesh spawner we can use uh multiple trees but for now we'll just add one tree this tree is from the modular neighborhood back uh this Oak one yeah so now our trees are spawned on all the points and you can see that they are all exactly the same there is no randomization and to create that natural randomization we'll use a node called transform points let's visualize it using the debugger and will give all these trees a random row to my rotation between 0 and 360 on the z-axis and as you can see the all the trees are rotated randomly and we can also give it a scale minimum and maximum let's keep it one to two now we have a much more natural looking environment let's hide the trees for a second using e which will disable the trees and you can see all the rotations and scales uh you can see that many trees are actually overlapping in that wouldn't happen in real world so we need to remove these overlaps and there is a note called self pruning this node should get the job done but you'll see that nothing really happens and the reason is it works according to the bounds of the points and not the meshes that have been spawned on them so if you can see that the bonds of these points which we can actually visualize right here they're not really overlapping and it's because the bounds are not really the size of the trees themselves so we need to increase the bounds to this approximating to the size of the trees for that we can use a node called Bounce modifier and let's attach it before self pruning let's visualize it for now I'll turn the trees off uh we'll scale it in x X as uh to about 4 and Y also to about 4 and in positive Z round 10. so this is almost the size of the trees so let's see now you can see that overlaps are gone this is before and this is after let's get our trees back and this looks much better that we are done with our trees let's create our blueprint for the road so let's go into the blueprints folder we'll create blueprint class of actor let's call it BP underscore wrote let's open this up and hit attach a spline component make the spline a little bit larger so that when I drop it into the level it is visible select this BP underscore Road and search for tags and we'll add a tag called Road no now uh why we are adding this tag you'll see in a few minutes let's go to the construction script create our road along the spline uh I have created a road section already in blender and have imported into unreal and we'll be using that one so let's use a for Loop node to go through all the points of the spline we'll get the spline and get its number of points get number of spline points now we know that the index starts from zero and spline points start from one so we need to subtract one tracked it and that becomes our last index now while looping through for each point we'll add a spline mesh component and this mesh component will be the road section this is the root section let me show it to you it's a very simple wrote and uh I have an asphalt material from Mega scans let's assign that one for each spline mesh component that we add we need to set its start and end point so we need the start position and start tangent so for the current index which will also be our current point let's get location and tangents flying point this becomes our start position and start tangent now the end position at end tangent will be the next point so we'll take index and add 1 to it and get the similar values of location and tangent now the target will be our mesh component itself so attach it and we need to attach all these components so we'll use attach component component we'll use the spine mesh component as Target and default scene root as parent let's compile it should work let's see we'll drag and drop this road let's create some role so it's like working fine a road is looking good but there's obviously a problem that the trees are getting spawned on this road so let's fix it what we'll do is we'll spawn a few points on this spline and use their bounds to remove the points or of these trees that are overlapping with the road so let's create another PCG graph called PCG Road here we know that the input is going to be a spline so let's use a spline sampler and instead of using the subdivision we'll use distance which will create points at fixed distance and the distance increment will set to 5000. and we'll use the same distance for spawning the houses on both the sides as well let's give the output save it let's open the main graph and drag and drop this road PC subgraph now you can see that in input we don't have access to any spline so we actually have to use the node called get spline data and we need to tell this node that which spline do we need and we will use an old world active filter and we'll get our spline by tag and as you can recall we used a road tag on a blueprint so that's the one we'll use and if I press d I can see the points but right now I can't see it because the bounds are very small so in the rode subgraph we'll use bounce modifier let's scale it up 2500 say a thousand in say now these this is a good enough bounds to remove our trees and also spawn our houses let's go into a main graph and we'll be using a note called difference we'll be using this node to remove any overlaps between all the tree points and the road points and you can see that all the trees along the spline are now gone now along these same points we'll be spawning our houses so let's use uh transform points and shift these points to one side let's say first we'll shift them say about a negative 2000 and why let's visualize so these are the houses on the left hand side we'll again use same transform points for the houses on the right hand side so let's make it positive two thousand and also rotate them 180 degree because the houses are supposed to be looking at each other and now you can see these are on the opposite side and we can merge both of these streams of data together these are houses and the bonds are quite large actually so let's decrease the size now I will not be using bounds modifier let's use a different modifier which is called extense modifier this will do the same thing but I will show you the difference between bounds and extends and Bounds we have access to both Min and Max uh say positive and negative side of the dimensions but here we only have a single value to control both the positive and negative so let's use it and it will use a multiply instead of set and we'll multiply the bounds by say 0.2 and 0.5 let's uh much closer to the size of the houses and let's spawn static mesh now the house that I'm going to use one of them is from the modular neighborhood pack itself and second one is from sketchfab this is free model by Tech developers which I'm using let's add it so we now have two houses spawned randomly on both the sides of the road now there is one issue that on the sharp Corners we will obviously have a chance of overlaps we'll use it again we'll use the bounds to get rid of this so we'll use self pruning now you can see the overlaps are gone so this is the end of the first part of this tutorial and second part we'll create uh some details like the fences and bushes and some more trees if you like this video please do share subscribe and like and see you in the next video
Info
Channel: Maddys HUB
Views: 26,008
Rating: undefined out of 5
Keywords: unreal engine, unreal pcg, unreal engine 5, procedural content generation, realtime, gamedev
Id: C-_RYWevAW0
Channel Id: undefined
Length: 22min 7sec (1327 seconds)
Published: Sat Jun 10 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.