Skip to main content
Getting Started

Harvesting Foliage

Step 1: Implement the Foliage Plugin Interface​

When foliage is harvested, the plugin sends the rewards to the first of these that implements the Foliage Plugin Interface: the Instigator (the Controller passed to the damage node), the Instigator's Pawn, or the Damage Causer.

Open your Player Controller or your Character, and add Foliage Plugin Interface under Class Settings → Implemented Interfaces.

Implement the Foliage Plugin Interface

This unlocks two events:

Foliage Plugin Interface events

EventCalled when
On Foliage HarvestedThe foliage was harvested. Receives the Foliage Actor and its Rewards.
On Foliage Error MessageThe foliage could not be harvested, for example because the wrong damage type was used.

See Foliage Plugin Interface for details.

Step 2: Add the rewards to your inventory​

Each reward has a Reward Name and a Number of Rewards with a Min and Max value. Pick an amount between Min and Max, for example with Random Integer in Range, and add it to your own inventory system.

Adding the rewards to an inventory

info

The interface events run on the server. Update a replicated inventory from here, and the clients will see the change.

Step 3: Apply damage to the foliage​

Apply point damage or radial damage to the foliage, on the server. This example does a line trace from the player's view and calls Apply Point Damage on the hit:

Apply Point Damage to the foliage

The plugin handles the rest. The first hit replaces the instance with your Foliage Actor and applies the same damage to it, so the first hit already counts as a harvest.

Damage must be applied on the server

Damage applied on a client is ignored. In multiplayer, send a Server RPC from the client and apply the damage there. See Multiplayer Harvesting.

Harvesting without damage

For berries, mushrooms and other things the player picks by hand, use Interact With Foliage instead of damage. See Interaction and Pickups.

Next steps​