Interacting with Foliage

How can i add individual health to the trees? using the class of foliageinstancedstaticmeshcomponent for all my foliage trees makes that everyone share the same health. I tried to add a shake effect when hit the tree but the same happens.
Thanks!

Hey there @Vitoresthor! Welcome to the community! So you’ve got the right path, but remember that all of the tree instances share the same actor, so you need to use the functions the class provides to make any changes to the trees individually. For instanced based classes this is the update instance transform function. Here’s an example of how to make it do a little wiggle/shake timeline when you hit it (threw it together in 3 minutes so it’s a bit messy sorry)


However, the health part get’s to be more of a question of how you want to implement it. Some games want persistent health for the trees, where if you hit it once today and once tomorrow it retains the damage. However other games tend to just toss the damage after a different tree/block is hit to avoid having to worry about saving/loading damage data. There’s so many paradigms in which you can handle this, but since the foliage instance system is meant to be lighter weight than normal SMs/actors I’d assume you’d wanna retain that and not make them all BPs. So the best option would be setting up a manager that handles the tree’s HPs (and likely where you’d put your function to shake them) that also keeps track of when they are destroyed and can keep the array updated that way.

2 Likes

Hey thank you so much for the response.
I ended doing the shake very similar as yours, but instead of a timeline, i added a bool variable and a delay, to shake the foliage while that variable is true (however i think your solution is better and much more organized).
And for the life system, first i create an structure and made a loop that iterates through all the instances and assigns the structure to them, and when the the player hit the action button, i set again the structure to the hit item (by the raycast) but substracting some points to the life.
I’ll leave the Event Graph in case someone needs something similar :sweat_smile::

Sorry for the mess, i’m still trying to learn how organize better this thing.

1 Like