rdInst Tutorial 43 – rdInst Custom Spawn Nodes in PCG
Last Updated: 1st September 2024
Tutorial created using rdInst version 1.43
rdInst version 1.43 contains some custom StaticMeshSpawner Nodes to spawn rdInst instances rather than the built-in ones. These can be useful for optimization (singleton instance manager) and also for directly manipulating the instances.
Note: These nodes are compatible with UE5.4 and above.
By default, these routines are commented out as they require the PCG plugin to be enabled, to re-enable them follow Step 1. or contact me on my discord channel and I can send a link to download the enabled version.
The “rdInstSpawnStaticMeshesWithIndexes” node adds a custom attribute to the point data containing the indexes used by the instances – you can then manipulate them directly from the index. It’s also very simple to add proximity swapping (Proxies) to the instances – either for a complete mesh, or for specific instances.
This tutorial will create two simple PCG volumes and populate them with trees via rdInst instances – when one shows, the other is hidden and visa-versa with a trigger box.
Step 1. Enable the PCG custom node in the rdInst Source Code
As the PCG plugin is marked as beta, the custom nodes and PCG component manager are commented out in the code and require a few lines be edited in the source code along with a build. Alternatively, you can contact me and I’ll send a link to download the built version (for rdInst owners).
In the source folder, you’ll find a number of files prefixed with “rdInstPCG” – 3 in the public folder (.h files) and 3 in the private folder (.cpp files). Just remove the comment “/*” at the top and the “*\” at the bottom of each of these files.
Then in the “rdInst.Build.cs” file, half way down there is a commented out “//” line including PCG – remove the comment.
Then build.
Step 2. Create a new project and enable the PCG plugin.
Create a new project, and enable the PCG plugin from the Plugins window – then create a new level from the Open World template.
Step 3. Create a PCG graph that spawns on the landscape
Now create a new PCG graph, position it in the level, then open it up in the PCG editor and add the script below. With the rdInst Static Mesh Spawner with Indices selected, add a Mesh Entry and set the StaticMesh to your mesh.
Note that when you inspect the Node, there is an extra attribute in the PointData with the StaticMesh index recorded.
Step 4. Duplicate the graph in the level and position away from the original
Now the PCG graph is made – duplicate the existing one in the level and move it away until there is a gap between them.
Now select them both, and in the details panel find the “Generation Trigger” and set that to “Generate on Demand”. As rdInst Instances are recreated at BeginPlay – the PCG volumes must either be set to “Generate on Demand”, “Generate at Runtime”, or spawned manually when needed.
Step 5. Create a new BP subclassed from Actor for a trigger
Create a new Blueprint from Actor. Open it in the Blueprint Editor and add a Box Collision Component. Add Begin Overlap and End Overlap Events to the Box.
Now add two variables of type PCGVolume to the Blueprint, make them public so they can be edited in the level.
Implement the Begin and End Overlap Events as shown below:
Add one to the level and position and size it so it completely surrounds your first PCG volume, expanded to cover half the gap from the duplicated volume. Point the PCG_Vol variables to each of the PCG volumes in the level.
Step 6. Done
Now just position the player start to near the perimeter of the trigger box (or your camera) and play the level. You’ll see the volumes clear and spawn when you cross from inside to outside – note how fast it is.