Download

Component not receiveing updated health value from function

hi guys,

Having a problem with an enemy health blueprint, I’ve been following a tutorial but making a few changes here and there to suit my own projest but essentially everything is fairly straight forward.

I have a projectile that hits an enemy, checks for a tag (Enemy) and if it finds it, it carries out another function called “Damage Enemy”.
A value of 50 is sent to a “Damage” input on the “Damage Enemy” Function.

Damage enemy is inside a library Blueprint and it carries out another function called “take damage”.

Take damage casts to my enemy character (Called “Grunt”), gets the characters health (Set to 100) and passes both the “health” and “Damage” (from the projectile) Variables to another function called “Take Damage”.

The “Take Damage” function subtracts the damage (50) from the health (100), checks if enemy health is <= Zero (where it destroys the actor) or >0 where it returns the value of “new health” back to the “Damage Enemy” function.

I know everthing is working to this point because if I do a print string from the returned value “New health” it outputs 50 which is correct however…

This information does not seem to update the enemy characters health (So every time I shoot the enemy it returns a new health value of 50).
The target in the take damage node is set to “Target Enemy Health” which is an actor component added to my enemy character blueprint.
I have attached some screenshots below, hopefully somebody will be able to see where I’ve gone wrong.

Finally it might be worth noting that although there is the EnemyHealth component included in the enemy character blue print, it is not actually called in the event graph anywhere.

c2bb939a8eb85fb29941185bdf90bb89ac5e78d9.jpeg

b0c2b3f680cdc49319f2e05df77b6a4041125b33.jpeg

Thanks in advance for any help you can offer with this! Pulling my hair out at this point!

Dave

Your Grunt Character has a Health property, which is passed as a parameter to the “TakeDamage” method. When this variable is set to the new value? (NewHealth)

As far as I can tell from the tutorial the health variable is pulled from the cast to grunt character and fed i to current health in the Take Damage function. Take damage then returns the updated value and this should target the enemy health component in the grunt blueprint and update the health value there.

You mean to the right of Take Damage? If you’re not setting the enemy health to the new health there you’re not actually changing the amount of health from the maximum health.

The Health variable will not update automatically, there will be no manipulation of this variable since you are making your own custom component for this.

To solve your problem, inside the “DamageEnemy” function you would just drag the health again from the same source, but this time set it to the resultant “NewValue” from the TakeDamage function. This will do the trick for you.

Hi guys,

Thanks for the help, I’ve actually decided to strip things back a bit as I was getting a bit lost with all these enums, libraries and function calls. Think I was trying to run before I could walk! So, I’m now doing everything inside the character blueprint where I can and hopefully somewhere down the line I can refactor things in to classes and make everything more streamlined.

Thanks again,

Dave