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?
- 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.
- 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.
- 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).
- Populate some data into the data asset, making the same number of entries for Name and for GrammarString fields.
- 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.
- In your PCG, add a node to get the new graph parameter. Use the inspector to verify that you see the soft object path.
- 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.
- 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”.
- 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.