Healing of damage over time

Good morning all,
I would like to create a function that would be based on the damage received by the character. It should include the fact that the character can receive the same type of injury multiple times, for example: low, medium or severe, and that they heal within a time determined by the age of the injury.
I’m thinking of using one or more array to do this, but I’m not sure how to arrange all of this at the index level.

Do you have an idea ?
Thank you in advance for your replies

An actor component is a decent choice for this.

When the player is injured create a new instance of an actor component and add it to the player’s blueprint. The component is responsible for tracking damage data and its timer can modify values over time. The player can query the components and check what is currently inflicted.

Each component can remove *self *from the player when the injury is fully dealt with.

Thank you, do you have a visual example to give me?

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.

Thank you very much, indeed it helps me. I haven’t gone further than simple variables and loops in actors yet. I will be able to take it to the next level :slight_smile:
On the other hand I do not limit myself to a single character, but there must be several of the same type, that’s why I specified that I would use it as a Table.

Can you, please, show me an example using tables, from the perspective of several characters?

Not entirely sure what you mean by *table *here (an array?); but if your party runs into a trap, you could hurt them all like so:

edit: To clarify, if I were to make a trap, I’d have the trap actor spawn the appropriate actor component on whoever enters the trap. This way you can have many different traps and they all work on an individual basis.

For anyone else who *also *likes to set world on fire and wonders whether actor components could be useful here:


https://forums.unrealengine.com/core/image/gif;base64

This will destroy anything that falls in in 3s. vid: https://i.gyazo.com/83e340c607bbde42ea813f5628bfe70f.mp4

Hello everynone,

I have a problem with “Vent dispatcher”, it is not accessible. However, I think I have correctly connected all the nodes together, not without difficulty for the reason that I do not know them all. On the other hand, I do not know if “Vent dispatcher” is configured correctly. I have a character health count, but no health return.

Can you tell me that, please?

](filedata/fetch?id=1825244&d=1603460320)
Indeed it is a table and not a table;) (thank you Google translator)

Other than that I was imprecise about the number of characters that appear in the games, their number is continuously increasing and decreasing. Imagine an anthill, with births that can be multiple queens. As the brood has grown exponentially, there are also deaths, which can be due to accidents (injury).

You will need to post screenshots. I don’t know how you wired it up.

An array may or may not be necessary. You can create an event driven system (as demonstrated above) that registers relevant events (when the ants are spawned) and never worry about who holds what index in an array. Array index manipulation is tiresome, can be slow and is prone to mistakes if one is not careful.

In the Event Graph of the component actor :

In the function :

The character :

The widget :


I have there a problem with the Event “Regain Health” which is found in the Event graph of the actor component, I cannot fill it in correctly. What should you put in the target of a “Cast to”?

I though the idea here was to heal automatically as time goes by… It would make little sense to call it the way you’re attempting. It’s the added component’s job to do it - that’s the whole point of this exercise. Whoever was given the component via HurtPlayer will be hurt and recover automatically, you do not need to worry about it.

On the other hand, if you want to do it manually with a widget button:

Get All Actors off Class -> For Loop and fire the event / function you need. There’s no need to cast.

Considering this is our event in the player ant:

You can then do this in a widget:


https://forums.unrealengine.com/core/image/gif;base64

I’m not sure why you’d want the call below - it contradicts what you originally requested.

In fact the button is there to simulate what inflicts damage on the character. I am not sure I understood your demonstration correctly, I will work on it …
I don’t see how the Event Hurt player is performed in the first part of the exercise

I still have the same error with “Bind Event to ED Injury Healed”
Using the Debug, I found a track, the recover health variable remains at zero.
To move forward I need to solve this problem, I’m counting on you :wink: