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
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