Unreal Engine 5.2 PCG Tutorial - Skyscrapers and Flowers Using a Single Custom Blueprint

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone I have made a custom blueprint element node that allows me to take a point and copy it upwards which has allowed me to create these miniature skyscrapers and then I realized I could create this and then I realized I could create this and this and this little I don't know car graveyard art project and these little car flowers you know I think a bumblebee would really like this flower a little Transformers joke all six of these things use the same custom node just in a different way and what this node does is it takes an offset and every time it runs through it it will copy the points off by that offset so in this case it's copying the points up by 300 every time it also accepts a rotation so what this thing does is it rotates by negative three and negative 5 every time and then copies them up it accepts scale these things are getting a little tinier but you can see it more with these these things are getting a little bigger the farther out they go and then there's a minimum and maximum height to tell it how many times to copy it upwards so without further Ado let me show you how to create this thing I'm going to start off by creating a blueprint type actor BP underscore let's call it copy points tutorial I'll also go ahead and create a PCG graph PCG graph PCG underscore copy points tutorial and I'll go ahead and create the blueprint element now PCG Blue Print element and I'll call this B PCG underscore copy points tutorial so in the blueprint I'm going to add a bunch of variables these are what I use for these configuration values first one is going to be offset that'll be a vector next one is going to be rotation which is a rotator and these three are basically the transform absolute rotation and that is going to be a Boolean and this lets me toggle between World rotation and absolute rotation so if I go back here this one is using absolute rotation which makes all the points rotate this direction and this one is using local rotation other than that they're exactly the same if you look at this offset value back to the blueprint scale so that I can make these things get bigger or smaller as they go height which is an integer let's call it height range actually hit range integer Min height and Max height and so all of these are going to be public except for height range height range I'm going to do something else and that is in the construction script I'm going to take Max height and subtract Min height from it and then I will set a height range to this value that way I only have to set the starting height and the top height and I'll automatically calculate this height range compile and Save now I can add the components so I'll add a spline component and I'll add a PCG in this PCG I'm going to set to copy points what just happened there copy points tutorial there we go compile save and I can just drag this into the world let me go ahead and update this spline right now and I will make the spline if I click on the spline here I can edit it I'll make the spine a closed loop and that should be done with the blueprint now in the PCG graph it's going to be fairly straightforward I'm going to start off with a get spline data active filter can be self since this spline and the PCG live in the same blueprint then I'm going to do a spline sampler and this I want to change it to distance on interior I can leave it at 100 and 100. then a projection node I'm just going to use landscape height for the Target and I can uncheck project rotations because there are no rotations coming in here next I'll do a bounds modifier and for this I want to set it to negative 200 negative 200. 200 200 and that's because my walls are 400 wide and four walls means I'm going to have a 400 by 400 box so this sets the bounds to 400 by 400 and let's just do 0 to a thousand that way if I tilt the buildings or anything they will the bounce will intersect and prevent them from spawning over each other next to self-pruding node now I'll toss in a transform points node this if you don't want to rotate your points is kind of unnecessary but in this case I do want to rotate them you might not want to rotate them because a lot of cities the points are on a square grid so it wouldn't make much sense to rotate the buildings but in this case I'm not building an actual City I'm just doing an example of how to build this thing next is a density noise node but I'm not going to put that in yet because I want to show you why I'm putting it in so after that comes the copy points Loop and then the static mesh spawner so let's start off with the static mesh spawner and the mesh entry I will use is the wall with a window and let's see there we go we have some wallets but they are just single walls they're not squares they're not encapsulating building so what I'm going to need to do is take the starting point of the static mesh which is either this side or this side it doesn't really matter and I'm going to move it in four different directions and rotate them in the proper direction to create walls so for that I can just use four different transform points node I'll put them after this one that does the random rotation so that all of these are based on this round of rotation because all of these are rotated locally they'll all inherit this rotation all right for this I could go through some trial and error and try to figure out which point is which like 200 on all of these okay so I've moved it there and then I can rotate it by I don't know negative 90. there we go and now it's an X so that probably means that this is the center point but I've already done this work so I'm not going to bother redoing it if you're doing it by hand I suggest that you modify one and move it modify another and move it and go on from there just the slow process of updating all of these and this one is rotation zero all right let's see what we got and there we go so now I can build out the blueprints and that will live right here between these two so let me open this thing up okay the first thing I'm going to override is a node title override and I'm going to call this copy points tutorial this impacts when you drag the node out into the graph the name of the node itself the default name because you can change it and I'm going to check on the class defaults exposed to library and the category will be custom since that's what I'm using for all of my custom nodes and description is copy points with user defined offset rotation and scale okay now if I compile and save this I should be able to go into this tutorial and over under custom I see copy points tutorial I can drag it out in and it's named copy points tutorial and if I hook it up nothing is going to happen because I have inputs but I don't have any outputs I'm not actually doing anything with it yet so I'm just going to go on here and the next function I'm going to overwrite is execute with context this will be a fairly standard setup if you've watched any of my previous blueprint tutorials you will recognize what I'm doing here first I'm going to set context promote it to a local variable and call that context and I'm going to take the input and break the PCG data collection and this tagged data is going to go through a for each Loop and I'll hook that up to the set each time in the for each Loop I'm going to break the PCG tagged data and I will cast that to PCG spatial data and hook that up that spatial data or so Point data with context and hook up the context here and then I'm going to run this all through a variable Loop I'm using a variable Loop instead of a Point Loop because a variable Loop lets me return a variable number of points instead of a single point and because I'm going to create points in a range of Min Heights to Max height like 10 to 30 or whatever I choose it's going to be a variable number of points and I'll show you when we get inside the variable Loop but it outputs an array instead of a single point which is how this is all handled in context it's going to be context and in data is going to be this point data with context once it's complete I'm going to make PCG tagged data and this I'm going to add to array and this array I'm going to actually promote to a local variable as well and I'll call it PCG tagged data array so I'm adding this every time instead of just sending it to the output because this for each Loop is going to run through multiple times so this allows me to continue adding these points and the results of the for each Loop every time all right that's about everything when the for each Loop completes I need to hook it up to the return node and the return node is going to be this PCG tagged data array that I then make a PCG data collection and hook that straight on up and now I'm going to go into the variable Loop body and if I just hook up this endpoint to the return value it'll make an array there's not really anything in it just the points that I've sent in but I should be able to inspect this and select the debug object and I see 21 points and before 21 points so it's working all right this variable Loop body this is where things get a little messy I'm going to set this point to point I'll be reusing it and a couple places such as here let me break the PCG point and for this I only need transform and density so I'll uncheck everything else and let's start off with the loop to do that I'm going to need to hook up some variables so I'm going to create the same variables in here that I have done in the blueprint so that's going to be offset as a vector rotation as a rotator absolute rotation as a Boolean scale as a vector that wasn't Vector there we go height as an integer and Min height I don't need Max height because Min height plus height is going to be the maximum height that we care about okay now I can expose all of these and if I compile and say if I can go back into the PCG graph and expand this and we see all of these values we'll have to do one more thing to actually start making use of these values but for now I'm not worrying about that let's finish off this blueprint let me break the transform and right I said that we'll start off with the for Loops so I'm going to take density and multiply let me hook this up here instead and let's take height so first we'll calculate the random height that we're using and we can multiply it by density but the problem with just doing that is if the height is a range of let's say 0 to 10. then when you multiply it by density density is zero to one and then we're going to be truncating it instead of rounding and so if you truncate 0.99 times height it's going to come out as a maximum of 9 instead of a maximum of 10. so to fix that I can add 1 to it and potentially this would result in a height of one higher but that'll only happen if density is exactly equal to 1 which should be pretty rare all right for this I'm going to change the outputs to integer by right clicking on the output pin and now I can add Min height to it and so now we have the range of the minimum height to whatever random height range we want to go to and now for this I can create a for Loop and first index I'll start with one last index is going to be this okay if the index equals one it's going to be the very first point and I want to actually just send that straight through I don't want to do any rotation I don't want to do any scaling on it so I'm just going to say if it equals 1 go into a branch and now I'm going to add it to an array add points to a add array the array I'm going to promote to a local variable and I'll call it PCG Point array and now if it's anything else let's finish this up if it's anything else I want it to set the location rotation and scale so let's start off with location I can add offset to it and make a transform but if I'm rotating these points then just adding offset will make them go in a single direction as opposed to continuing to curve so I need to offset them by the rotation so for that I can plug it into a rotate vector and I'll plug rotation into the rotate vector and then I can hook that up but if I'm scaling the points up or down the offset should get bigger or smaller accordingly otherwise you'll get gaps or a lot of overlap between your points so I need to multiply offset by scale and then I can plug that into the rotate vector which then plugs into the addition which then goes out into the location Let's uh yeah move that up there okay so the rotation is a little more complex so let's just do scale take an easy win I'm going to multiply scale by this new scale and output it into the transform and now rotation so I'm going to start with the easy one combine rotators and I'll take rotation and this is going to be if absolute rotation so World rotation is set to on that's all you need to do if it's not then you need to do this little work around convert rotator so we're converting the Rotator over to a local rotation that we can then work with and then converting it back to World rotation something like that I didn't quite understand exactly why we have to do this but I do know that it works so so we invert it combine the rotators which is the same action that we're doing here and then we invert it again and now I can add a select option select rotator and I'm going to plug this absolute rotation into the selector and if I have absolute rotation checked I'll select the absolute one otherwise I'll select the local one and then I can return that into rotation instead and now if we get to the for Loop and find that we're not working on the first point we need to set this transform to the point transform and for that I can do a set members in PCG point and I can find that by dragging the point out and finding set members in PCG points I'm going to check the transform and hook up this transform and then I can just hook up the false here we can reuse the same add node because in either case we're modifying the point or just sending the point straight through and then this right here just uses the point that we've modified if we've changed it and lastly we need the return node so I can grab this array the PCG Point array that we're adding to and drop that into the return node and then hook up the return node save all right so now we can go back to the PCG graph and hook up all these variables for this I'm going to use a get actor property which allows me to pull in variables from the blueprint because I have point of the actor filter itself I could change it to anything else just like a spline and in this case just like the spline we can get it from the blueprint so the first active property is going to be offset and I can just follow along this guide here I just need one for each of them I need six of these rotation rotation absolute rotation absolute rotation scale height and midnight oh it's not height it's height range which might mean I do need to change this one to height range so let me change that to height range height range compile save back here now I can hook all of these up and let's see what we can do so for these I know that they're 300 height because I've looked at the static mesh so I'll set the offset to be 300 every time I'll leave the rotation at nothing I don't need to set it scale I'll set to 1 on everything if you leave it at zero then the first one will be scale one the second one will be scale zero and everything after that will be scaled zero mid height five Max height 10. and there we go so there is one problem here and everything is pegged to the max height one two three four five six seven eight nine ten eleven since they're 11 that means they're all density one so let's take a look inspects and where's the density density one for everything and earlier on in the tutorial I said that I put a density noise here well this is why I waited to do it I want to show you what happens without it so if I just hook up a density noise right here there we go and now if I drag this around it'll be random points random Heights all right let's say we want to add additional meshes to randomly spawn I'll change this one to just be a flat wall 400 by 300 and this one to be well with a door 400 by 300 as well and you see here that every single wall on each building is the same and that's because the random seed that I'm copying over here is the same for everything I'm I'm copying the exact random seed so if I inspect this you can see a bunch with the same random seed I could modify the random seed in here but it's possible that I want to reuse the same random seed so what I'm going to do instead is add a transform points node here and it might be perfectly valid to have buildings that are all the same like maybe you're selecting a different color so you want the buildings to all be the same different color that's perfect good use case now I've hooked this back up and I can click in the transform points here recompute seed I could also do it in here on each one of them it just depends I like to do things in bulk in a single place as opposed to on each individual one that might not be the best idea I don't exactly know how PCG graph works so I don't know if sending it through this transform points and recompeting the seed is going to take longer to generate than just having each of these generate the seed but in practice it doesn't seem to be affecting me too much and there we go they are random Heights they have random doorways and I can set them to five to let's say 30. I can set there rotation to 15 5. given this weird twisty thing I can set absolute rotation so that they are swinging the breeze instead I can set their scale to uh get bigger as they go and quite work with this but well that's how it goes play around with this knock yourself out tell me if there is anything cool you do with it I'd love to see it I'll see you next time
Info
Channel: Michael Royalty
Views: 17,985
Rating: undefined out of 5
Keywords:
Id: 6yTw9zHrr68
Channel Id: undefined
Length: 29min 15sec (1755 seconds)
Published: Thu Jul 06 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.