Skip to main content
Guides

Harvester and Inventory

The Foliage Harvester Component does the player side of harvesting for you: the trace, the server request, range and cooldown checks. It is also the link between the plugin and your inventory. The plugin rolls the drop chance and the amount, then asks the harvester what fits.

Step 1: Add the component and harvest​

Add a Foliage Harvester Component to your Character. Call Harvest from your input. It returns true if something was hit.

Harvest from input

In Mode you choose how it harvests: Interact for berries and mushrooms, Damage for axes and pickaxes with the Damage and Damage Type you set on the component.

Step 2: Receive the rewards​

Bind On Rewards Received to know when rewards reached the inventory, for example to show +3 Wood. It is called on the server and on the owning client. In this example the binding is made from Begin Play:

On Rewards Received

Each reward is a Foliage Reward with a Reward Name, an Item and the rolled Amount. The Context tells you the Resource Row, the Resource Name, the Foliage Actor and the Location.

On Rewards Rejected works the same way, and is called when a harvest was refused because the rewards did not fit.

Step 3: Connect your inventory​

Make a Blueprint child of the Foliage Harvester Component and override these functions. They run on the server.

FunctionWhat to do
Can Receive RewardReturn how many of the Reward fit in the inventory right now. The default accepts everything.
Give RewardsAdd the Rewards to your inventory. It is only called with what Can Receive Reward accepted. The default calls On Foliage Harvested on the Foliage Plugin Interface, so existing projects keep working.
Get Tool TierThe tool tier checked against Required Tool Tier in the row, for example from the equipped item. The default uses the Tool Tier of the damage type.

Put the Item of a reward in the Data Table row under Rewards on Harvest. It can be any asset or class from your inventory system.

The harvester is found on the damage causer, the instigating Controller, its Pawn or Player State, or the instigator or owner of the causer. Without a harvester, the rewards are sent to the interface as before.

Step 4: Choose what happens when the inventory is full​

Set Reward Overflow on the row:

OptionResult
Drop As PickupWhat fits goes into the inventory, the rest is spawned as a Foliage Reward Pickup.
Keep In ResourceNothing is given and no use is consumed if anything does not fit. The player gets Inventory Full on the interface and On Rewards Rejected. Rewards on Depletion that do not fit are still dropped as a pickup.
DiscardWhat fits goes into the inventory, the rest is lost.

Reward pickups​

The pickup class and how long a pickup stays in the world are set in the plugin settings under Inventory. A pickup gives its rewards to an actor with a harvester that overlaps it, or when you call Pickup on it. What still does not fit stays in the pickup. Make a Blueprint child and use BPE On Rewards Updated to show the item mesh or the amount.

Reacting to harvests in the world​

Bind On Foliage Rewarded on the Foliage Manager for quests, statistics and achievements. It runs on the server only and gives the rewards that were really given:

On Foliage Rewarded