rdInst Tutorial 39 – Chopping down PCG volume Trees

This tutorial goes through each step needed to spawn a PCG volume with random trees (no collision on the trees for fast spawning) – then bake the data from that in realtime for use with rdInst.

We’ll create a Tree Actor that gets chopped when the FirstPerson character shoots it – the tree falls when chopped a specific amount of times.

The Tree Actor tells the rdProxy when it’s been chopped down, instructing it to use the “Destroyed” mesh at the fallen rotation. This then gets used when the Actor is out of distance.

The Tree meshes used for the PCG volume have an area on the trunk that is controlled by a per-instance custom data value – they draw the area in a light brown and introduce some normal bending – the number of times the tree has been chopped is stored in a SaveState and the instance custom value is set – all trees retain their chop state.

To top it off, the tutorial is multiplayer – each client sees the trees being chopped by other players.

Step 1. Create a new project based on the FirstPerson Template

The first step is to create a new project. Base it on the First Person Template.

Step 2. Download the Tree Content (or project)

Now if you’re creating from scratch download the Tree Content zip linked to at the top of this page and unzip into your projects content folder. If you’ve started with the download project, the content is already there.

Step 3. Create a Choppable Tree Blueprint

Now we create a Blueprint for the choppable tree.

The Tree Mesh used has 3 knife cuts around the trunk – the center knife cuts vertices have been painted white while the rest are black. Note that the mesh must be used with Nanite disabled as Nanite doesn’t support vertex colors (yet).

Create a new Blueprint and open it in the Blueprint Editor, navigate to the construction script and create a dynamic material instance for the trunk as shown below:

Now add a function called “SetChoppedAmount” and in it, set a scalar material parameter to a value between 0 and 1 (0=unchopped, 1=fully chopped).

That’s all that’s really needed for now.

Now Open the trees Trunk material, and add the code to change the BaseColor and the WPO like below:

It would be fairly easy to expand this to only chop in the impact direction – you could paint each vertex in the middle knife cut to values representing their angle around the center, then apply WPO to only the angles needed. The Blueprint could store the current values for each vertex so you can chop in multiple directions.

You could also use ISMs rather than a StaticMeshComponent if wanted, just add a per-instance custom float to the ISMC and set the “ChoppedAmount” in there (and reflect that in the material).

Step 4.

Step 5.