How can I manipulate stored values?

Anyone have any advice on this?
I’m looking for a way to create a variable say, Player Health, then I want that variable to be able to be manipulated in different ways. For instance, when object touches my character it does 10 damage to that Player Health variable. But also, if I pick up an item, I can permanently increase the Player Health variable by 10. Where do I first place this Player Health variable so that I can alter it different ways. Is it in the My Character BP? Or Do I need to make a BP Interface for it?
Still trying to understand how the flow works for creating a system like this. Thanks!

I would put it in my character Blueprint and then make two functions on the character, one called “TakeDamage” and one called “AddHealth”, both of these should have an integer or a float (your choice) as input. Now obviously “TakeDamage” is simply going to subtract the input value from the “PlayerHealth” variable and clamp it to make sure it doesn’t go below 0, you can also make the “TakeDamage” function fire a custom event on the character when the health reaches 0, it could for example fire a “OnPlayerDied” event. The “AddHealth” function is just going to add the input value to the “PlayerHealth” variable and clamp it to make sure it doesn’t go above a maximum value (for example 100).

Now when you want to deal damage or add health to the player from another Blueprint you can simply use the “Get Player Character” node to get a reference to the player (you may have to cast it to your specific character Blueprint before it works).

I hope this helps, if not let me know and I will try to assist further.

In addition to Spiderhund, If you’d like to permanently increase a player’s health, you need to have a variable for the player’s maximum health. Clamp the PlayerHealth variable to min ‘0’ and max ‘MaxPlayerHealth’ so that it doesn’t go below zero and higher than player health.

If the player picks up an item that boosts its maximum health, increase the ‘MaxPlayerHealth’ variable. From there you can either heal the player for the difference, heal the player right up or not, your choice.

Ah yes storing the max health in a variable is more structured and easier to manage should you wish to change it in the future :slight_smile:

UE4 also has a build in system for managing damage types and stuff like that. I’m not entirely sure how it works as I haven’t used it yet but here’s a link if you wish to read more about it:

Thanks for the information! I’ll give it a shot