# Healing of damage over time

**URL:** <https://forums.unrealengine.com/t/healing-of-damage-over-time/152498>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [October 22, 2020, 1:06am UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498 "2020-10-22T01:06:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phylogenius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Phylogenius](https://forums.unrealengine.com/u/Phylogenius)\
**Post date:** [October 22, 2020, 1:06am UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/1 "2020-10-22T01:06:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [October 22, 2020, 6:39am UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/2 "2020-10-22T06:39:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Phylogenius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Phylogenius](https://forums.unrealengine.com/u/Phylogenius)\
**Post date:** [October 22, 2020, 10:44am UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/3 "2020-10-22T10:44:51Z")

</div>

> [@Everynone](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [October 22, 2020, 12:19pm UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/4 "2020-10-22T12:19:09Z")

</div>

The component has 1 function (top) and 1 custom event (bottom):

 ![player.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/6/f/a6f63b55bc6ef5f8ff772c212e85e3c333be23ab.jpeg)

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.

 ![a6f63b55bc6ef5f8ff772c212e85e3c333be23ab.jpeg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/6/f/a6f63b55bc6ef5f8ff772c212e85e3c333be23ab.jpeg)  
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.

---

<div class="post-metadata">

**Author:** ![Phylogenius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Phylogenius](https://forums.unrealengine.com/u/Phylogenius)\
**Post date:** [October 22, 2020, 1:12pm UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/5 "2020-10-22T13:12:51Z")

</div>

> [@Everynone](#):
>
> 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 🙂  
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?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [October 22, 2020, 1:32pm UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/6 "2020-10-22T13:32:37Z")

</div>

> [@Phylogenius](#):
>
> 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 🙂  
> 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:

 ![firecomp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/2/d/e2d8e273bf2fedc2f51b089210aa02843972adbd.jpeg)

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:

 ![firecomp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/2/d/e2d8e273bf2fedc2f51b089210aa02843972adbd.jpeg)

 ![e2d8e273bf2fedc2f51b089210aa02843972adbd.jpeg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/2/d/e2d8e273bf2fedc2f51b089210aa02843972adbd.jpeg)  
https://forums.unrealengine.com/core/image/gif;base64  
​  
This will destroy anything that falls in in 3s. vid: [https://i.gyazo.com/83e340c607bbde42ea813f5628bfe70f.mp4](https://i.gyazo.com/83e340c607bbde42ea813f5628bfe70f.mp4)

---

<div class="post-metadata">

**Author:** ![Phylogenius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Phylogenius](https://forums.unrealengine.com/u/Phylogenius)\
**Post date:** [October 23, 2020, 1:26pm UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/7 "2020-10-23T13:26:48Z")

</div>

> [@Everynone](#):
>

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?

 ![event dispatcher.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/0/d05a0f80cdab71c32cd7d1cf425869eee48a26bb.png)](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).

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [October 23, 2020, 1:31pm UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/8 "2020-10-23T13:31:27Z")

</div>

> [@Phylogenius](#):
>
> 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?

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

> [@](#):
>
> their number is continuously increasing and decreasing

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.

---

<div class="post-metadata">

**Author:** ![Phylogenius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Phylogenius](https://forums.unrealengine.com/u/Phylogenius)\
**Post date:** [October 23, 2020, 3:30pm UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/9 "2020-10-23T15:30:57Z")

</div>

> [@Everynone](#):
>
> You will need to post screenshots. I don’t know how you wired it up.

In the Event Graph of the component actor :

 ![domage retablissement event graph.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/c/4c4b92adbc6c612e3b0c9517bfc77393788a9269.png)

In the function :

 ![domage retablissement recup et sante.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/6/d6a10b07865d6325ebd5d3621f6b89d14d47185c.png)

The character :

 ![personage.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/c/f/cf6cbced92a2140c2833cdd063ad89623e7653c5.png)

The widget :

 ![Widget.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/c/7/c786b7477e0564d71aa5a706fc102d7461f4e2ad.png)  
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”?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [October 23, 2020, 4:24pm UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/10 "2020-10-23T16:24:39Z")

</div>

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:

 ![Screenshot 2020-10-23 173228.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/3/6/f36b30a1139964c8ee2f8f40007083c5b77e7666.jpeg)

You can then do this in a widget:

 ![f36b30a1139964c8ee2f8f40007083c5b77e7666.jpeg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/3/6/f36b30a1139964c8ee2f8f40007083c5b77e7666.jpeg)  
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.

---

<div class="post-metadata">

**Author:** ![Phylogenius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Phylogenius](https://forums.unrealengine.com/u/Phylogenius)\
**Post date:** [October 23, 2020, 7:05pm UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/11 "2020-10-23T19:05:16Z")

</div>

> [@Everynone](#):
>
> I though the idea here was to heal automatically as time goes by…

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

---

<div class="post-metadata">

**Author:** ![Phylogenius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Phylogenius](https://forums.unrealengine.com/u/Phylogenius)\
**Post date:** [October 23, 2020, 11:38pm UTC](https://forums.unrealengine.com/t/healing-of-damage-over-time/152498/12 "2020-10-23T23:38:35Z")

</div>

> [@Everynone](#):
>
> …

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 😉
