The component has 1 function (top) and 1 custom event (bottom):
Variables:
- Injury Type is an enumerator (Mild | Moderate | Severe)
- Health Modifier - how the component affects Player Health
- Recovery Time - how long it persists in seconds
When added to the player’s blueprint, we run the *Set Recovery and Health *function (as seen below). The component is then configured according to the Injury Type; here, we set Recovery Time and the *Health Modifier. *We also Set Timer By Event which will run the Recover Health event every 1s. Finally, the function returns some data the owning actor may want to use.
The event counts seconds left till full recovery and once the time is up, we notify the player via the Call ED Injury Healed (an Event Dispatcher) and then *Destroy *this component. Alternatively, you can punch in a float value directly into the Timer, but perhaps you wish to notify the player about the current state of the injury as the time goes by.
[HR][/HR]
And here’s how the component (Ac Injury) is added to the player’s blueprint.
https://forums.unrealengine.com/core/image/gif;base64
As soon as it’s added, we run the aforementioned *Set Recovery and Health *function, utilise the returned data to lower player’s health for the time being, and register the event which will eventually notify the player that the healing process is complete and the injury is no longer present. When this event fires, the player can recuperate health lost due to this component’s modifier.
You could *Query Injuries *if needed - this will find the pertinent components this actor owns. For example, the player drinks a healing potion -> fetch all components the potion can remove and destroy them.
[HR][/HR]
The above is just a super simple stub but is quite flexible and can be extended (and maintained!) easily. The idea here is to have a base component class and use inheritance to create various states that can effect the player - buffs / debuffs / over time effects / extra abilities and so on. Combining it with interfaces can create a truly potent and complex system.
For example, you could add an *isOnFire *actor component that will keep reducing the owning entity’s health until it’s extinguished (or the entity perishes as you can have the component destroy its owner). Do note that once you create a bunch of components responsible for various afflictions, you can instantiate them on **any **actor, not only the player.
If a fireball sets an area on fire, all legible actors can have their own *isOnFire *components added which can then be only removed by spawning an *Extinguish *component to cancel it out slowly - when the entity is rained on, enters water and so on…
The core strength here is that these are highly modular and reusable. [HR][/HR]
Also, do note that I’m not using any arrays here. You can, of course but there might be no need - depends on the complexity.
Hope it helps.