You Should Start Using Data Assets in PCG | UE 5.4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
since BCG has come out we've always wanted to control the amount of things responding dynamically be able to swap them out control the different properties of it but it's always been isolated into the static mesh spawner and while we could modify one mesh we could never modify how many variations and all the things that come with it now with 5.4 we're introduced to data asset support as you see here this is from the PCG biome setup we now have all the information we could want in here and we can specify it and we can have an array of them so we can have different variations and different meshes and have them all work together in unison so let me show you how do you create your own data asset setup so that way you can start modifying and dynamically changing all your static meshes in your PCG projects so to get started if you haven't yet go under edit plugins and search procedural and you want to turn on procedural content generation framework BCG just turn that on and restart the engine if needed once you have that set up we should be good to go so we're going to need a few things for this starting with the actual PCG graph so I'll just search PCG grab our a PCG graph I'll call this PCG Dynamic meshes and I'll make myself a blueprint class and we want an actor I'll call it BP Dynamic mes spline as that is what it is and let's go ahead and open the actor I'll go ahead and add ourselves a spline and I'm going to just deselect this end point right click on this point bline generation panel let's just make a big Square let's just say 1,000 units in size and then search for closed in the details panel for close loop and then I'm going to click here to select a point and press delete and that deletes the extra point that it creates at the very beginning when it recloses the loop and now we just need to add the PCG graph and plug in our graph now I can go ahead and compile and save and this is pretty much good to go so now we're going to need some new things that we haven't needed before in PCG we're going to need to create data assets and that requires three things variables which we're going to use structs for the primary data asset that holds that variable information and then the data asset itself but the good thing is once you create the actual primary data asset that is the one that houses all the variables and all the functionality so then you create data assets off of it and you can create all the different variations you'd like so to start with I'm going to right click and search for struct for structure and just call it sore Dynamic meshes I'll go ahead open it up and this is where we're going to specify all the things that we actually want to have in this static mesh that we want to have access to so things we're going to want to have access to is the static mesh itself I'll search static mesh and select static mesh object reference and I'll go ahead and call this static mesh I'm also going to want potentially a float for the weight and by weight it really means how much priority does one thing have for example if you have something with a weight of one and one thing with a weight of five the thing of with five will have five times more likely to spawn the weight of one then I would like to also introduce a scale now for the scale I'm going to make it a vector and I'm going to set the default to be 111 cuz we can actually modify the scale in all three axes and let's introduce a rotation and that will be a rotator and by default will be 0 0 Z that's is a good start you of course can add all the new things you want you can add blls you can do whatever you you want it's all up to you this is just where we're starting out here so I can show you the different aspects that I'm using here so now we need the primary data asset so I can right click go to blueprint class and under all classes search for data asset and we want the primary data asset here I'm going to call this PDA for primary data asset Dynamic meshes and let's open it up so this looks very much like a regular blueprint but there's no construction script and there's no viewport so what we want is to have access to those variables we created so let's create a new variable I'll call this Dynamic mesh and then here we want to search for the struct that we created so I'll search sore Dynamic meshes I'll go and select it and then if you right click on S Dynamic meshes you can just convert it to an array because we want to have this as be an array so we can dynamically add and remove meshes as we want and then we want to expose it that's pretty much all we need here so I'll go and compile and save this and now if I right click I can search for data asset and here you want to select your primary data assets so I'm going to search for PDA uncore and here it is PDA uncore Dynamic met I'll go ahead and select it and I'll call da for data asset and this is going to be now what is actually going to be inside of it so I'm going to populate it with random shapes for example so I'll call this da basic shapes because this is now what you can use in create a forest props whatever you'd like and it's now going to be using the same data asset and you can just duplicate them around and create variations of it now we have this let me show you I'll open it up you can see we have now the dynamic mesh and I can click add element and in here we now have access to the static mesh the weight the scale and the rotation now the weight actually that I'm looking at it probably needs a default of one at the very least so what we can do is go back to our structure and change the weight to one now I Believe by default this tab is actually right here so you just need to swap over if you don't see it but I like to have them side by side because is just easier for me to work with like so I can go and close out of that now because I updated the struct I need to go into PDA Dynamic meshes and recompile it unfortunately strs have this slight problem of whenever you make changes to it anything that is utilized it needs to be recompiled now it's recompiled you can see it is updated here and so now we can go ahead and populate this now I'm using basic shapes here so for example I can use a cube I can go ahead and add a new array element let's grab ourselves a cone and let's add one more maybe give ourselves a cylinder now we have the option to control many aspects of this so by default let's go ahead and make the cone five times more likely to appear than the cube and the cylinder will also be twice as likely compared to the cube so now we have these functions let's go ahead and utilize them in the PCG graph with the 5.4 a few things are different and I'll try to go over the things that are different so you know some things are the same like get spline data and getting ourselves a spline sampler this has not changed at all in fact we need to do the same thing as before on interior for a dimension and we control the Interior Space sampling I'll make this something like 500 and I'll just make the actual interior border spacing actually the size of those cubes inside of them to be 250 let's go ahead and drag out this blueprint spline so we can see it in this level we go come here and make sure it's unbounded that is still needed in 5.4 and you can see there's an error one or more rows of the spline interior failed to sample ensure the spline points are not overlapping if I was to select it and Sample it with the D key you could see it is actually sampling just fine now for some reason this is still an error that occasionally happens even in 54 even though I have no overlapping points in fact if I move all of these you can see none of the points are actually overlapping there's only one in each location but once I make it bigger the error goes away I'm not sure why this is the case but that is the simple solution that if your points are really big you might need to increase the size so that way it is not actually worried about them overlapping each other now we have this it is time to actually start utilizing the new data asset functionality if we go to the graph settings above we can add ourselves a new parameter which is basically a variable click new property and we're going to change this to PDA the primary data asset that we created Dynamic meshes and you want an object reference and this is going to be a single one we don't need the array because it itself is holding the array and then from here I'm going to just rename this I'll just call this mesh array and if I click on none here I can go ahead and select our da basic shapes as the default so we have something by default always to use it right click and get mesh array and then we can start utilizing some of the new nodes in 5.4 and one of them is a new get property so if I drag out of here and search get property you can see get property from object path so we go ahead and select this now the input source is going to be last but we can of course plug something else in here if we wanted to and here in the get actor property we want to change the property name and the name is actually from our da basic shapes and it's this this Dynamic mesh which is what we called it now if I go to PDA Dynamic meshes that we created originally you can see Dynamic mesh is one word and here it splits into two but the original variable is altogether so here we need to specify property name Dynamic mesh alt together and you see the error goes away so now to use this we can use another new node called match and set attributes so if I search match and set attributes you can see if you hover over it it matches or randomly assigns values from the attribute set to the input data so this will automatically assign everything we need if we just select this out plug this into match data so that from here I can go ahead and grab ourselves a static mesh spawner and instead of the mesh selector type being the selector weighted we want to do it selector by attribute and the attribute name will be static mesh you see and I put it in with a space so I'm putting a space in here and you see the error has disappeared and now if we take a look here we now have our array of meshes all populated in something to note of course they're all the same size they're on a grid exactly because that is how the sampler is and they're all equally prevalent in this environment even though we've specified we want different actual weights to them so how do we use the weights in the match and said attributes there's actually a nice match weight attribute checkbox we can turn that on and then well we need to use weight because that is what we called it so our attribute is called weight I'll go and type that in and now if I come over here you can see the cone is now appearing far more often than the cube and the cylinder is slightly more often now it might be hard to tell so if we go ahead and go to our da basic shapes I can just set set the cone instead of five I can just dynamically set it to 10 and you can see it automatically updates if you're enjoying the content I would love you hit the like button and subscribe if you haven't to see more awesome tutorials like this so that's great but how do we now use the scale rotation to actually modify our values so there's two ways to get the actual attributes from your meshes one is from directly from the points because we've added this information to the points if I hit a and here in the bottom left corner I select the drop down and select our PCG Dynamic meeses you can see this is all of the attributes that it has including if I scroll all the way to the right you can see it has scale XYZ is that is the new values that we created here's the static mesh and has the path to it of course it has all the information that it used to have like the actual point position the rotation Etc but if we sample this with an the a button we can see this has all this information as well so we can grab the information from here or from here depending on what you're trying to do if you're grabbing from here you might think you get attribute in fact that's not the way it works and I'm not sure why they designed it this way to get an attribute if you want a specific one you need to get a delete attributes it stumped me originally at first two in the operation you have delete selected attributes but also keep only selected attributes so if I wanted to I can just keep only selected attributes one we can keep for example is rotation and now with it's selected I hit a and you can see it has only kept rotation roll pitch and yaw so if you need just an attribute output you can get it this way we're going to be using the points version uh this version is a little more complicated because you will need to use Loops so I'll be showing you a way without Loops to get you pretty much variations and be able to use the points as the base so we have the scale let's utilize that first so what we can do is move this over to the side let's multiply the scale by the scale that we have inputed now again because in the data asset we've piped in all of the attributes as you saw it has all this information I go ahead select from this out node and I can plug both of them into a and b now the input source if I hit this plus button I can select scale this is the original Point information scale and you can see it's dollar sign scale and then I want to multiply by the scale that I have piped in again if we select this and press a you can see we just have scale here it is also called scale so without the dollar sign we just type in scale for input two and the output Target basically where are we saving this information to I want to save it back to scale in our case input one is already the scale so I can leave it as output Target Source or I can set it back to scale specifically because maybe you want to grab your positioning and multiply by your scale instead of as the scale you could do a lot of very interesting things you don't have to save it back onto itself but with a scale plugged in we go ahead and plug this all the way through and you can see nothing has changed but that's because our scale is all one if I take this cone and let's just change this to two you could see it is now changing the size nice let's go ahead and move this up a little bit so be a little bit above the ground you see it's only affecting the cone if I want to I can go ahead and make this cylinder just really tall and if I wanted to I could just go ahead and just delete it and it'll now work with only two of them so that's great so you think well we can do the same thing for rotation right not quite so for rotation the way I originally wanted to do it was use an ad node because I want to just add the rotation that we specified there and if in this ad node I go ahead and select rotation and in the input source 2 type in rotation again error error rotation from pin a is not a supporter type reran for some reason and maybe this is just me misunderstanding something it really does not like you doing all three rotations in one go what you can do is modify only a single axis at a time so if for example if I go ahead and select this multiply node or select this and just press a again you can see the original values here have rotation. roll. pitch. yaw and so do the new ones that we created rotation. roll. pitch. y so in this ad we can do rotation. yaw and rotation. yaw and you can see that it is now no longer complaining and if I plug this in and go back to our data asset we can go and rotate them now it's going to be hard to tell if a cylinder or a cone is rotated but if we rotate this Cube and let's say rotate them by 60° you can see they're being rotated now they're all rotating in unison and we may maybe want to rotate them in a range and we don't want to maybe scale them all uniformly too because everything right now is very uniform the complex method is to use a loop and Loops is something that I'm still trying to wrap my head around because it's seems like 20 steps to do something that should be relatively simple so I'm trying to figure out a way of understanding it as a a very basic level so I can show you guys as well so one thing you might want to do is if you want to for example do it randomly you might think okay let's give ourselves a transform points node and then we could just go ahead and well we can either pipe in random rotation here for 360° and that gets us the result we want but you know maybe we want to use our actual information here because we have this rotation if we try to use this rotation and plug this into to rotation Max you can see a warning multi- entry attribute set was found on override pin rotation Max we will only use the first entry to override so unfortunately because our data asset has multiple array items it is only going to do the first one it is not understand how to get this information from the specific one it needs and to do it you would need to use a loop and actually go through them one at a time make sure they match it's a more complicated process but I do have a way of doing it without all this complex mess of a way of getting that same Randomness without a single Loop so instead of this I'll remove this transform points and we're going to modify this multiply and this add so the thing we're going to be using actually is alert alert Blends between the first number and the second number you might think okay well that wouldn't that mean that all the points are going to be the same because it's still going to be a single ratio that's where you can use some interesting fun things in PCG to modify that so for a scale I'm going to take our scale and I'm going to plug it into B and I take the output that that we had originally and plug this into the out this is going to go to B and then I'm going to just drop this down and just take this original and plug that into a cuz we want the original to be what it was and this multiply that is basically our maximum so whatever the point was it's going to go from that value to the multiplier so that way if you actually modifi the points to be smaller before it still maintains that and it scales them relative to that actual original size now what do we put in the ratio for the ratio I'm going to search attribute noise and you might be familiar with this this is how you do a random density a lot of times but we don't need to modify the density in this case we just use the value the randomness that it creates per point so in this attribute noise the output Target is not going to be Source we're not putting it back into itself I'm just call this scale ratio and it could be 0 to one that is fine and go ahead and just drag this around give it a random seed and I'll plug this into the ratio now it's giving us an error but that's fine what we need to do is take this scale ratio just go ahead and copy it and in our lur instead of last for this input source I'll type in scale ratio and now we need to modify the input source one instead of last we want to specify we want scale and for input source 2 we want to also modify the scale because here we're going through it and we're outputting the modified multiply back onto scale so here it is not going to be modified and here it is and now if we take a look you can see that they're actually different heights now so if we come in here and can modify the scale of the cylinder if I make this 10 you can see it's even more varied and we of course do the same thing for the cube make it taller make it wider and it's not all going to be the same width it's not all going to be the same height it is now randomized based on that attribute but now let's do modify the rotation so it be the same way we're going to use alur we detach here grab ourselves aler plag this into a this can go into output this can go to B I'll take this attribute noise and just duplicate it over and plug this in into a ratio and this attribute noise I'm going to change this from scale ratio to rotation ratio and then I'll copy it and I'll change the seed on this as well and here in the lurp I'll change scale ratio to rotation ratio and here we want to modify the rotation so let's modify rotation. YW to the same thing rotation. y now it is complaining about the rotation ratio pin ratio is not a supported type Rotator but what's really complaining about is this last so what I'm going to change is this last here and we're going to set it to be density and to make sure there's no issues down the line I'm going to change this attribute noise at the beginning also instead of last to be density so we're modifying the density this value doesn't matter because outp putting it to a different location anyway we're not modifying the density actually so now with these lurs in place now you can see that the cubes are actually not rotated despite in here we have specified 360 rotation even though we have this ad and it's set up correctly and it's being put back into Source it's not properly blending although it worked for the scale one and what we need to do is in here just like we did in the attribute noise change the output this output Target I'll go ahead and call it modified scale copy it over to this input to modified scale and here I'll call this output Target modified rotation and I'll go ahead and copy it and in B I'll put in modified rotation and now you can see it is actually properly rotating everything around and things are being scaled accordingly now as always the project files are going to be available on my patreon where you can join these wonderful people here in supporting what I do it does mean a lot and if you have any questions feel free to leave them in the comments below or join the Discord where you can go ahead and join like my people and we can all learn together thank you again to these patreons let's get back to it so now that we have this and this is all working great how do we now Swap this out very easily with anything else we want want to use take our da basic shapes I'll duplicate it and instead of Da basic shapes this will be da Forest I'll go ahead and open it up and you can see all our information is still here but you can go ahead and delete it it's just a little bit simpler than right clicking creating the new data asset and going through that all again but now I can go in here search tree and grab ourselves a BCG tree let's grab ourselves another one and I'll grab ourselves a little small one now I want a lot more of these small ones give it a large number here and these can be actually rotating randomly within 360° and let's have these guys actually scale between 1 and three in all axes and I want these guys scaling between one and two in all axes so that's great but we don't actually have this here so to modify it I'll ahead and make a copy of this just for myself all you need to do is come in here in BP Dynamic mesh spline 2 go down to PCG and here you have the graph but under parameter overwrite if I open that you can see here's our da basic shapes I can go ahead and select this check it on and now if I drag in da Forest as simply as that all our meshes have now been swapped over to this I'll go drop this down onto the ground and you can see we now have all of the trees with all all the parameters and the variations that we specified and you go above and beyond you can create Bulls you can do a lot of things now this is just the base setup of how to start accomplishing this for yourself with this you can now go out and create much more complex things that you could in the past with a new 54 features and if you like to see some other features that 54 introduced check out this video right here where I go over how to use the actual PCG biomes that was just introduced
Info
Channel: Procedural Minds
Views: 2,879
Rating: undefined out of 5
Keywords:
Id: QRxuq_aEptI
Channel Id: undefined
Length: 20min 14sec (1214 seconds)
Published: Sun May 19 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.