rdInst Tutorial 6.9 – Baking Proxy Scan data at run-time


Spawning Instanced Static Meshes is a lot faster when they have no collision, but most of the time you do want to be able to interact or collide with them when in proximity.

That’s where this routine comes in handy – you can spawn your ISMs in something like a PCG volume with no collision, and then instruct rdInst to swap add collision boxes to the closest ones – you choose the distance to scan.

You could convert the PCG volume to a rdSpawnActor like in Tutorial 35 – that can spawn at any distance simply by setting the “distance” value to something non-zero – and it handles Proxies for you, but this time we want our PCG volume to spawn the trees randomly each time – the SpawnActor uses baked data so is the same each time.

The ISM data can be split into multiple rows and columns – if you’re spawning a large area – it can significantly reduce the amount of scan iterations to break them into smaller areas – all you need to do is specify an amount of rows and columns, rdInst does the rest.

In this tutorial we will spawn a PCG volume at run-time, pass it through the “rdBakeVolumeTransformsForProxies” routine and then attach a Proxy Actor with collision.


Step 1. Create a new level

Create a new level based on the Open World Template.


Step 2. Create a PCG Graph

Now we create a simple PCG Graph containing a few trees. This is the same as in Step 2 of Tutorial 6.8.

Make sure that the meshes have collision turned off in the StaticMeshSpawner Node.

And set the instance settings for rdInst to have no collision, you can do this via rdInst by right-clicking on the meshes and selecting “rdInst->Instance Settings” – turn off collision in the window that opens:

Alternatively you can set this by adding a rdInstAssetUserData class to the AssetUserData and change the settings in there, see Section 6 of the Reference Manual.

Drag one into the level, then find the “Generation Trigger” setting and change it to “Generate on Demand”.


Step 3. Create a new Blueprint for the Tree Proxy Actor

Create a new Blueprint Subclassed from rdActor:

Call it “BP_TreeProxyActor”, Add a Cylinder and shape it like the Tree trunk, but slightly larger.


Step 4. Set the Proxy Settings for the Mesh

Now navigate to the Mesh Asset (the Tree Mesh) in the Content Browser, right-click and select “rdInst->Proxy Settings”. In there, set the Proxy Type to ShortDistance, tick “Proxy all Instances” and “Don’t hide Mesh”, and set the Actor to the BP class we made in Step 3


Step 5. Create a new Blueprint to Spawn the PCG Volume

Create a new Blueprint based on rdActor.

Call it BP_Trigger_PCG. Add a variable of type “PCGVolume”, mark it public:

Add a Cube (so we can see where it is) and a collision sphere, make the radius for the sphere 200.

Now with the Collision Sphere still selected, scroll down to near the bottom in the details panel and add an Event Handler for the Begin Overlap Event.

Add the code below to spawn a PCG volume and add the Baked Proxy data, and of the Proxies. Only objects that have Proxies assigned in their assets are converted. If you want to scan some objects (with others having proxy asset data) – you can use the “rdBakeVolumeTransformsForProxiesX” function, it also accepts an array of sids to include.

Drag the new Blueprint into your level, somewhere close to the PCG volume but not in it – set the “PCG Volume” variable in the Blueprint details panel to the PCG Volume Actor that’s in the level.


Step 6. Done.

That’s it, now just play and move to the cube, then around the trees to watch them swap in the collision and cylinder.