Download

Harvesting system - reusing code in a smart way

Hello everyone,
I’m new to UE Blueprinting. I’m currently creating a harvest system. I was able to make a harvestable tree after checking for a hit (note 1: ignore the errors in the LowerHealth Function as I’m changing it atm) note2: The apply damage note is to delete a text widget (‘press e to interact’ that I spawn on collision overlap)

With some changes, I was also able to make a rock harvestable but I wanted to re-use as much code as possible. So I started grouping as much as possible:


But then I ran into some problems in the LowerHealth function:

I’m basically copying everything all over again because I can’t find a way to extract the ‘right’ actor from the array so I can re-use the code.

I’m not sure if my thinking process is correct so if anyone can provide me with some feedback on this code, that would be much appreciated!
Thank you in advance,
Lino

Hi man,
Take a look at “Interfaces” WTF Is? Blueprint Interface - YouTube

Basically
You have actorA that is a “wall indistructible”
You have actorB that is a “wall destructible”, you give to this actor access to an interface “Show damage”
You player can attack , Whatevet he hit, he try to use the interface ShowDamage
No matter the actor
ActorA , dont know the interface and will do nothing, but also not give error
ActorB, will know the interface, and will create your widget with damage and stuff.