Red screen connected to health

So im looking to have the opacity of the screen blood correspond to how much health the player has. (just like COD) ive looked online for this but it doesnt seem like anybody really does this…

I made a quick video showing you how I set it up. I started with a texture that was already transparent (I removed the white background in Photoshop).

Inside the Material, I created a scalar parameter and set the Slider Max to 1.0f, this is because we only want the opacity between 0 and 1. Next give the Scalar Parameter a name (This is important because this name is used in the HUD Widget later.

Inside the HUD Widget, I created a new variable called OverlayMat which is a dynamic material of the blood splatter material. This is so we can set the value of the Scalar Parameter in the material when the player gets damaged.
I also created a custom event that took in 1 variable, a float called PlayerHealth, so that this function is only called when the player is damaged rather than on a tick. I got a reference to the OverlayMat and “Set Scalar Parameter Value”, set the Parameter Name to whatever you called the scalar parameter in the material.

We need to do a tiny bit of basic math to convert the health (presumably 0-100) to 1-0 so when the player is on 100 health, the overlay is completely invisible and when they are on 0 health it is completely opaque. To do this, we pass in the player health and divide it by the Max Health (Note: in the video I divided it by 100, but you would divide it by whatever your max health is) This returns a value between 0 and 1. However if the player is on 90 health for example, 90/100 = 0.9 which means if we used this value, the blood splatter would be almost completely opaque when at 90 health! So to invert this, we can do (1 - Return) where Return is the value of PlayerHealth/100. So now we would have (1 - 0.9 = 0.1) meaning the blood splatter will be barely visible at 90 health, just like we want :slight_smile:

In the Player class, every time he takes damage all you have to do is call the custom event in the HUD and pass in the player’s health. This function can also be used if you have a health regeneration function too, so as the health increases back to max health, the blood splatter will fade out.

Hope this helps dude!

If you need any help with anything let me know, or add me on Discord @PickledFerret#1651

Works great! Thanks! Only thing is that the Opacity when he is dead is only at like 50%, where i want it at 100%. Do you know how to fix this? Idk if i changed a setting or did something wrong

Double check that the scalar parameter in the material, the default value is set to 0.0. Also is your character’s health between 0-100?

Inside the custom event in the HUD Widget double check that the PlayerHealth is being divided from the MaxPlayerHealth. i.e. in the video I did (PlayerHealth / 100.0) the 100.0 pin should ideally be a MaxPlayerHealth float variable stored on the player that you pass in to the custom event, same as how the PlayerHealth is.

If neither option work, can you reply with screenshots of the Material, HUD and Player BP (where the TakeDamage event is being called).

Cheers!

Well part of it may be because my players health is 0-1. so the dividing was unnecessary. And yep the scalar is correct.



Huh… that’s interesting, firstly you’re right you don’t need the (float / 1.0) node. Right-Click the TookDamage function in the Player BP and Add Breakpoint then play the game, every time you take fall damage the game should pause here, just check that it’s still being called each time. (Note: When the editor pauses, your cursor might be constrained to the game window still, press Shift + F1 to get out of this), then click Resume at the top. If this is being called the correct number of times. If not the only thing I can think of right now is in the HUD Widget after the (1 - float) node, add a (float * float) node and multiply it by 2.0 to see if it gives a more fuller blood overlay.

yep its being called everytime as its supposed to, although i didnt realize the false was hooked up to it. So i just mulyiplied it by 2 and it works great now! thanks! Although i do have another problem im stuck on if you know much about destructable meshes! if yuou could help me with that too thatd be great!