Hi,
I have recently been trying to use my Data Assets for mesh selection to make my graphs cleaner. This was pretty easy to implement with the Static Mesh Spawner, since it is made for spawning Static Meshes and therefore has all of the options built in to match Soft Object Paths to the spawned mesh.
Since Spawn Actor doesn’t seem to have this option, only presenting us with a “Spawn Attribute” instead. I am quite unsure how this attribute works, since I can’t find much documentation on it. I couldn’t find a way to tie it to the Soft Object Path to the meshes to replace the Static Mesh it spawns either.
Since I found that this sort of thing isn’t particularly well documented yet, I figured I could help a bit by sharing how I make these small and simple things work.
What I found works perfectly is to create an Actor Blueprint that is going to be our template for spawning Static Meshes with a really simple workaround, while also keeping parametric flexibility. This actor only contains a Static Mesh (don’t forget to change from “Movable” to “Static” in the object details) that we modify in the construction script.
Unreal seems to resolve the Soft Object Path by itself, so you don’t need to convert the Static Mesh variable to Soft Object Reference. I’m not sure it makes any difference either.
Note that if you’re going to instantiate a lot of this actor, it’s preferable not to add too much logic at runtine, and to keep it simple in the construction script if possible. But if you simply change the mesh in the construction script, then the overhead should be negligible compared to a StaticMeshActor.
If you need help creating the Data Asset, i recommend watching this video to understand how to create a Data Asset and link its attributes to your points.
Once in the PCG Graph, you can simply connect your Match And Set Attributes to your Spawn Actor. You should have something like this by now:
We now need to adjust the Spawn Actor’s settings a bit. In Template Actor Class, you will need to select the blueprint we created earlier. Then, you’re going to need to set the Option to No Merging ; this allows us to access new options, most notably the “Spawn Actor Property Override Descriptions”. Add a new Override, fill in your input attribute (you can visualize the attribute’s name by pressing A on the Match and Set Attributes to inspect it), and add your blueprint’s variable name to the Property Target:
This allows for better control of your PCG assets in my opinion, as you may change anything in the blueprint to allow for more overrides, and modify actors individually directly in the scene.
Now, if anyone knows a better way, simple improvements, or a reason that this isn’t optimized / simply bad practice, I’d love to hear about it!