Маке REALISTIC Paths along spline - Unreal 5.2 PCG

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everyone today I'll show you how you can make this uh spine p uh spawning random P generated along a spine that you have uh drawn in the level you can see every time I change the SP the new p is generated with random features along the sides of the road like trees or rocks vegetation and all of this part is based on this single level and it's picking random objects from the level based on the logic that we create in the PCG it's created similarly to the p in the electric dreams demo showed by Epic on the presentation of the procedural content generation framework I have the electric dreams project project downloaded here and this is the level that they showed if you download the project you can get the project from the unreal Marketplace if you go to the browse button and then scroll to the unreal feature samples it's the first one currently electric DS environment if you download it and open it you will see couple of levels in the content folder open the levels folder then the PCG then breakdown levels and open electric dreams PCG spine example and it contains this part if you edit the spine it's regenerating the p and it's using this level here to generate the pth random objects along the sides you can see it's a very detailed part and it's all created by this single level we'll actually reuse some of their custom blueprint logic to not recreate everything if you go to PCG folder then open the graphs folder the spine example folder and here you will find the spine example PCG graph in this graph they're using two custom nodes first one is this copy points with hierarchy and the next one is near the end it's apply hierarchy we need those two uh functions I'll show you briefly the function here it's not so complicated but since they're already created it we can reuse it instead of making it from scratch it's just applying the values that you set in the PCG properly to the uh instance level with your geometry to have everything placed by the rules in your PCG graph in the PCG folder then the assets folder then open the PCG custom graphs and here you have the apply hierarchy and copy points with hierarchy and I believe copy points with hierarchy we'll use this uh post copy points blueprint class so if if you select all of those three you can right click and then with asset actions you can migrate to your project by clicking this uh migrate button then choosing the content folder of your new project and this will move them so you can use them in your PCG graphs later now when you go back to your current project that you exported to you will have the same PCG folder then assets and then PCG custom nodes folder inside this folder you will have the three exported functions that we'll use in the PCG graph leave them for now and you need to create the level that you will spawn along the spine to create the path I have created this uh desert style road for the example of the project let's quickly recap what you need to make sure to include in this level in order for the path to look good I will hide most of the elements first start with the PT don't make it too long because in the corners and curves of your PT you need to have not huge segments so the PT doesn't look choppy it's it has a nice curve on it so I have sticked it around 3 m length for the rad also make sure that at the beginning and the end of the rad you have the pth lower than from the middle in that way it connects better on the on the change of swap that you can have in your Pats when it's going up here or down here also make sure that the Pat is oriented along the X AIS in the bottom left corner the left axis is pointing into direction of your pth then at the side of the pth start placing elements to define the pad shape I have created these embankments on the left and the right and then start to add extra objects that will be randomly placed along your side of your pad for example trees and to be able to spawn those objects randomly based on some Logic on the PCG you'll need to tag them so select the objects that that you're placing go to the details panel search for tag and here in the actor tax section let me delete this one it will look like this by default click on the plus sign and then add the tag so for all my trees I have a tag three I have three static meshes for the trees and they all have this tack then the next one is this small shrubs along the path this one and they have this tack as well the next one is the small walks along the path they have the tack small walk I have the big shrubs here they have the big shrub Tack and finally I have this big rocks element I have three big rocks this one this one and this one and they all have the tag and when placing elements that will be randomly placed along the side of your P make sure that they look fine by themselves so here if I hide two of the rocks make sure that your P doesn't have holes in it or other problems with the geometry make sure that each one is placed properly and if you want to randomize for example the rotation of the objects make sure that when you rotate your object it doesn't create any problems this will be a problem because the seam would be visible that's why you need to place the objects in such a way that they doesn't interfere with the the proper rendering of your pad so after you have done this you created the the section of the road and you tacked all the objects that you want to place randomly along the sides of the rad select all of the objects of your pad for me because I created them in one folder it will be easier to select by the folder so select all descendant of this folder then right click go to level and create level instance you can leave everything as default here here pivot type Center I mean z is important leave it like this so save the level where you want in your project I'll call it like this and now this is a single object in your level it's an level instance you can edit it by clicking in this edit button in the details panel or clicking control e e it will allow you to change the path if you want to make some changes later but for now I'm happy with this P when you create this level instance in order to use it in the PCG graph you need to do one more step so go to your level instance where you have saved it in your project right click on it go to scripted asset actions and click on PCG level to PCG settings this will create this uh PCG settings file for you and you will need this to use in the PCG graph so now let's create this uh PCG graph I'll go here inside my PCG folder and into the tutorial folder I'll create a new PCG P so go to p PCG PCG graph and I'll call it PCG desert SPS for example I'll create a new blueprint that will use this right click here create a blueprint class make it an actor blueprint call it BP desert P open the new blueprint and inside the blueprint add a SP component component that we'll use to draw our pth and also a PCG graph and for this PCG graph select the graph that we create the PCG desert P compile and save this blueprint now if I drag this blueprint into the level let's create a longer path let's go to the desert pth PCG that we created and we'll sample this spine so right click and choose the spine sample and for the spline we'll drag and we'll get spline data the the spine data will be taken from the blueprint so for the actor filter select self this will refer to the blueprint that contains this PCG graph this will select the spine and we place the objects based on a fixed distance of 300 CM that's the length of my path and now we need to use the blueprints that we copied it from the electric dreams environment first we'll need to the subcraft so right click and start typing copy points with hierarchy and the next one drag from this execute blueprint and here select apply hierarchy for this copy points with hierarchy note we need need our points that we want to copy to from the spline and the points that we need to copy will come from our PCG settings level that we created earlier so go where you saved your PCG level and the generated PCG settings file is here drag it inside and select instance now if I drag from the points to the copy point source this will copy all the points for the objects in my dirt path segment into the points placed along the spine connect this to the apply hierarchy Noe and after this we'll spawn static mesh spawner and we'll select by attribute the attribute name will be mesh these two notes are copying the path of the meshes and the materials and there copying the position of each of these meshes for our level and placing it along this spline so if you go back now to the level you'll see that at each 300 points we are spawning the level of the p and it's following the curve that we draw now what we'll need to do is just to randomize this p a bit and also to make sure that we are randomly placing the objects at the sides and we are not just placing them each time because it's easily spot that there is a repetition right now we don't want that we want our path to look more natural so before copying the points into our spine we'll want to randomize the path bit by rotating some of the segments the other way for this to work before copying the points onto our pth we'll change a bit the position of the points on the pad disconnect this node and after we sample the points each 3 m then we'll do a density noise this will add a random value from 0 to one for the density on each point and then we'll do a point filter we'll filter the density if the density is uh bigger than5 let's check this use content threshold and put 05 so for half of our points they are from 0 to one and we are only filtering the ones greater than 0.5 we'll want to transform points and the transform will be that will rotate them 180° in Z and for the other half that is leaving outside this filter we will do nothing so we'll just merge those points the ones that we rotated and the other ones and then we'll copy them to our static mesh spawner save this and now the path is a little bit more randomized some of the pieces are rotated the other way these rocks are on the left and these ones on these ones are left and these ones are on the right so this is a good step into the variation part of our poer the other thing that we will do is after we apply the hierarchy so we have the points we have them placed along the spine the individual points inside the level after the copy points with hierarchy and before the apply hierarchy let's make some space and here we'll place the randomization of each type of points into our level so do it the same way like here let's disconnect and now let's create a point filter into this point filter instead of density I will use big Rock tag I'll again use the constant threshold and this should be an integer because if I have this tack on the points they will have a value of one and the other way they'll have the value of zero so I just need to check if this one is bigger than zero and the type is an integer so all of the rocks will be filtered inside this Noe here inside filter and all the other points will be in the outside filter so for the Rocks I'll apply a density noise again from 0 to one then I'll apply a density filter then because I have two rocks on the one side of the road I don't want them to place together I want one or the other just to have a chance to be spond so I'll do a self pruning operation for the end I'll Transform the points to add a little bit of variation so let's say I'll add some rotation to them this way it will be a little bit more randomized so by this logic I'm using this note to not spawn big rocks on the same place of the road and this one is determining how much big rocks I'm placing along the path for now around half of the objects will have this big Rock Let's test and see we must first merge our big rocks with the other objects into our path let's use again this merge node and then connect to the end and now if you change the values in the density filter you will see that you get more or less big rocks at the side of the road let's say we want for example 20% of our tiles to have big rocks on them so we'll put the Bounce from 0 to2 we don't have a lot of big rocks on the side if it's too little for you do a little bit more three for example and now we need to do that for the other types of objects that we have for example let's do it for the trees because they are currently very easily poble that they're repeating into our scene so we know that this this part of the graph is only containing the rocks and we are merging with the other parts here in the end into the merch Noe let's add a little bit more space here let's disconnect for now this noes I'll add a comment here Rock placement and when we filter for our rocks the trees are left out outside in this outside filter points so we'll do again a point filter because this contains also the other types of objects like shrubs and the locks on the ground and the path itself that will not randomize at all so we'll do a point filter here we'll put the T three we'll use constant of in and now inside the filter we have the three points and outside we have all the other points so let's copy the same graph as for the Rocks we don't need the self- pruning because I actually want the two trees that I have on top of each other sometimes to place together this right branch of this tree it's separate object and that way I'll make it look like a different tree with three branches from the base instead of the two ones from the original one that way it will create a little bit more variation so that's why I don't want to use the self brunning node I'll apply a density noise then I'll filter some some of the trees and then I'll Transform them for the trees you can do a more Extreme rotation they will be rotated basically at any way they they can be placed so to this 360° in total so I'll merge the trees also I'll merge the other objects that I'm not currently placing randomly just to see the result now I don't have a threee on each patch of the P I have randomly placed the trees and you can control this by the density for example I if I want more trees I can put 0 five here if I want less 4.2.1 let's say I want3 and they are randomly rotated I also can put some random scale for the trees for example I'll scale them from8 to 1.5 that way I'll have some smaller and some bigger trees let's change the example to be a little bit easier to spot let's put 2 as a minimum it's not scaling the trees properly because I have forgot one step you can see see that if I change the values the trees are not changing that's why because I need to apply to attribute this apply hery note is making sure that the transform is applied from this relative transform node so into the transform points for our rocks and for our trees I need to check the y to attribute and then put this relative transform here I'll do it for the Rocks as well and now I have the tree scaling from8 to 1.5 now let's continue with the next type of object I'll add a comment here and say three placement the next one is the big shrubs along the side of the road I'll copy everything here I'll call it Big shrp I'll connect the outside filter to this filter disconnect it from the merch at the end so everything that is Rock we are dealing with here on the top everything that is three here the big shr now will continue Point filter we need to change to Big shrub and the same will be done for the small shps small shrp and and in the end for the walks along pth for small walk connect each outside filter to the next Point filter and then change the tag name small SHP and here small walk merge all of the results and at the end merch everything that is left not filtered by the tax and now you have a random placement of if each type of the objects in the scene and you can change every randomization variable here and by this filters and transforms you can control how are you placing the objects along your path this setup is basically the same as the one in the electric dreams demo but using more type of objects and placing them randomly along the side of the path to make it more random what you can do if you fold the last two tutorial to use the this Orient Point function for the mesh length I'll add 300 because that's the length of our piece after we sample the points we'll all Orient them with this function this can help you a little bit with the swaps in your TR let's disconnect and show you what's the difference so if I have it connected by default and if I add a point to this point in the middle let's add one at the end and we'll use this one if I had this point in the middle and I make my RO curf a little bit up there are some places that your road can show some disconnect let's try to break it move it a little bit here and now you can see I have um disconnection from the two pieces of the road the Orient Point function from our last tutorial can help a little bit in this so instead of connecting directly to the density noise you can add in the middle this Orient Point function and if you remember from our last tutorial for this Orient Point function to work properly we need to translate the path to be matching the beginning of the spine so after we Orient the points we will transform the points and we'll move them half of the length of our path so it will be 150 units it's a lot better now you can see the difference if I disconnect this Orient Point and I connect it directly to the transform points I have big problems with the slope even if I don't translate the points if I have it like it was by default I have this connection here so one thing that you need to address if use this Orient Point functions is that the way that we did it in the the last tutorial it doesn't take into consideration if you rotate the point and if you want to have this part on a side Swap and you want to rotate it you can see that nothing is happening with the road so into the Orient Point function we can make one change here where we setting the rotation for the point we need to take into consideration the rotation in the x axis our current point so get our in point let's break this point let's split the PIN for the transform let's split the PIN for the rotation so this rotation in X AIS I'll add to the rotation that we are creating here so let's disconnect this let's split this pin and we'll add the X rotations of our point and our calculated rotation based on the positions of the other points and after this we will make a rotator and we'll create we'll connect the calculated Y and Z axis and connect this Rotator here into the point that we are saving in the end of the function you can organize it a little bit better but you can see what's the logic here so we are just using the X rotation of the point into our last resulted rotation that we created for the point so compile and save this and now if I go back here when I rotate the P it will generate properly the swap angle that you set in the spine in this way you can easily add pads to your level they will look random you can control how much trees and how much of the big rocks you have you can add more categories that you put random objects based on the TX and with the Orient Point function it will make sure that you don't have this connection on the swaps if you see pieces like this you can just rotate the point slly to fix it this will be the previous point now everything is back to normal you can easily populate your level with natural looking pads if you liked this tutorial please like And subscribe the video if you have any questions write in the comments and if you have ideas for new tutorials please pleas also write in the comments as well and see you next time [Music] bye
Info
Channel: DK 3D
Views: 10,572
Rating: undefined out of 5
Keywords:
Id: nsQGYWQze7U
Channel Id: undefined
Length: 36min 47sec (2207 seconds)
Published: Sat Dec 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.