PCG Subdivision Submodule

Looking for some pointers or some general info on the PCG_Subdivision_Submodule as there does not seem to be any pointers to it online

Creating a PCG Blueprint that contains a spline, using the GetSplineActor and then using the Subdivide Spline Node, you can set the module as input on this.

We would like to be able to create a data table that contains a list of Grammar Attributes that can then be selected from a exposed param to change the Grammar String and Module to the new entry

currently trying to get this data table row back into the PCG graph but stuck on how to get it to go any further. Since DataTables arn’t fully supported in PCG yet with the module type (can’t seem to add a data table with an array?)

If I understand the question correctly, you want to have a parameter on your PCG graph that selects a row from a Data Table, and the contents of that row is the grammar string that will be passed to your Subdivide Spline node.

Assuming that’s correct, I don’t think you’ll need the custom PCG Element Blueprint; at least, I don’t in my graphs. You can either do this with Data Tables or with Data Assets. I have been moving toward Data Assets because I find it more versatile, so here’s an example of how to do that.

Decide how you want to structure your data. In the simplest case, you can have a Data Asset that literally contains just a single string that is your grammar, then you would make one of these for each grammar variant. What I recommend, and will illustrate here, is to have a Data Asset that corresponds to a grammar “set”, where each member of the set has a Name and a Grammar String.

As a use-case, let’s say you are making an open world game with villages that have unique architectural themes. Each theme will correspond to one Data Asset file, and within the file the Name will be the “thing” to which a grammar is applied. The names might be DefensiveWall, FarmFence, StructureWallGroundFloor, StructureWallMiddleFloor, and so on. The grammars are whatever you want them to be. Some themes may repeat module patterns (grammars) even if the meshes that are spawned for those modules differ, while other themes might sprinkle different module variants. It’s up to your designer.

Now, how to implement this?

  1. Make a Blueprint class derived from Primary Data Asset. This will define the schema of the data you are storing, and it’s a data-only Blueprint. Call it something like PDA_ModuleGrammarSet.
  2. In the PDA Blueprint, add a global variable called Name, of type Name, and a global variable called GrammarString, of type String. Make both of these into arrays. They don’t need any default values. Compile and save.
  3. In the content browser, go to the Miscellaneous category, make a Data Asset from your PDA type, and open it in the asset editor. Name this asset for one of your themes (assuming that’s how you’re organizing your data).
  4. Populate some data into the data asset, making the same number of entries for Name and for GrammarString fields.
  5. Now in your PCG graph, add a Graph Parameter that is of type PDA_ModuleGrammarSet (or whatever you called your PDA BP), and make it a Soft Object Reference. Set its default value to the one you just created in steps 3 and 4, or leave it empty. Either way, this is the graph parameter you asked for that will let you change the data without editing the PCG logic.
  6. In your PCG, add a node to get the new graph parameter. Use the inspector to verify that you see the soft object path.
  7. To that node, connect a Get Property from Object Path node. The Input Source can remain at the default value of “@Last”. Change the Property Name to “Name”. This node’s output should now be the contents of the Name field from your data asset. Set the Output Attribute to “Name” also.
  8. Duplicate the Get Property from Object Path node, connect its input to the graph parameter, and change the Property Name to “GrammarString”. Now this node should receive the contents of that column. Set its Output Attribute to “GrammarString”.
  9. Finally, connect both of these Get Property nodes to a Copy Attributes node, and check the box to copy all attributes. The output of this node will be a lovely attribute set that matches the names and the grammars one-to-one.

Here’s a screenshot of all four nodes and the data output:

There are multiple ways to use this downstream. You can Attribute Filter before passing it to the Subdiv Spline node, or you can use one of the Match and Set nodes, etc.

You can take this a lot further, too. Right now I’m using this technique with data assets that match a lookup key (“Name”) with a PCG grammar, but the module names in the grammar are themselves used as the Name key to look up the StaticMesh asset to spawn for each module. The list of module names mapped to StaticMesh assets is in its own PDA type, along with some other metadata, and I read all those in together in one part of my PCG graph so I can retrieve the mesh bounding box size to get the module size dynamically, and I pass that to the Subdivide Spline node.

I hope this is helpful to you.

I’m making a second post because I thought this would be less confusing than covering everything at once. There is another, equally viable, way to organize the data, basically pivoting the “data axes” of structure type and theme.

In my previous example, I proposed a data asset per architecture theme, and the names inside each data asset correspond to the structure type (fence, wall, etc.).

You could do this the opposite way: Make a data asset per structure type, and let the names correspond to your architecture themes.

So you would have DA_GrammarSet_FarmFence, DA_GrammarSet_BldgGroundFloor, DA_GrammarSet_Bldg_UpperFloor, etc., as your asset files. Then each file would have the same list of Names inside, for example, “NorthernProvincial”, “WesternReaches”, “ImperialPalace”, etc.

This approach, rather than the previous example, is probably how I would structure these. The main reason is that having the names be themes allows for an easy default – you can literally make a “theme” called “DEFAULT” – that is used for anything that isn’t defined otherwise. So maybe farm fences are the same all over your world. Fine. Just make “DEFAULT” and the fence grammar, and that data asset file is done. If your art director later decides the ImperialPalace will have different fence themes but everywhere else is still generic, just add that one row to the data asset and nothing else needs to change.

Again, I hope this is useful. I spend a lot of time thinking about the data relationships behind a game, so forgive me if I’m too deep in the weeds here. :slight_smile:

Thank you for this, just a quick one, got the modules working with a DA input so we can toggle the Grammar as needed, but the mesh spawner is having some issues

image

it’s setting correctly in the inspector with the mesh assigned to the correct module name (Turret, Wall ect)

but when looking at the generated PCG, its just repeating the mesh along the spline

but when you change the DA to other types, the symbol is being set correctly according to the Grammar passed in

Am i right in thinking we need to re apply the mesh to the point after the SubDiv ?

hopefully this can help others with this with limited docs on the topic :slight_smile: