# Optimal way to handle variable number of timers

**URL:** <https://forums.unrealengine.com/t/optimal-way-to-handle-variable-number-of-timers/399694>\
**Category:** Architectural and Design Visualization\
**Tags:** unreal-engine, architecture, CPP, question\
**Created:** [July 5, 2017, 3:22am UTC](https://forums.unrealengine.com/t/optimal-way-to-handle-variable-number-of-timers/399694 "2017-07-05T03:22:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![acxsasx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@acxsasx](https://forums.unrealengine.com/u/acxsasx)\
**Post date:** [July 5, 2017, 3:22am UTC](https://forums.unrealengine.com/t/optimal-way-to-handle-variable-number-of-timers/399694/1 "2017-07-05T03:22:18Z")

</div>

So I want different effects running at variable times to be affecting the character. I want the effects to be maintained in a database to allow for flexibility in tuning.

I am considering using a TArray of custom “Effect” classes (parented to Actor Component) to represent the various timers in play for a character. When I want a health over time buff on a character, I create the “Effect” class passing it a reference to the character. The “Effect” class will know to call the “Add health” method on the character. Maybe even pass in the method on the character the “Effect” object will need to call.

The “Effect” class will internally create two timers, one for the overall time of the effect and the other to fire off the incremental (if any). When the overall timer fires, it will call a method on the character so the character can remove it from it’s array. When the object is destroyed, it will handle the cleanup of the timers.

Anyone see problems with trying to do this?

---

<div class="post-metadata">

**Author:** ![HailstoneRyan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HailstoneRyan](https://forums.unrealengine.com/u/HailstoneRyan)\
**Post date:** [July 5, 2017, 5:03am UTC](https://forums.unrealengine.com/t/optimal-way-to-handle-variable-number-of-timers/399694/2 "2017-07-05T05:03:43Z")

</div>

You’d be better off utilizing the Tick of the component and the DeltaTime passed in rather than two separate timers. This way you’re using an existing system of the engine that’s already ticking every frame. Everything else sounds good!

---

<div class="post-metadata">

**Author:** ![acxsasx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@acxsasx](https://forums.unrealengine.com/u/acxsasx)\
**Post date:** [July 5, 2017, 4:26pm UTC](https://forums.unrealengine.com/t/optimal-way-to-handle-variable-number-of-timers/399694/3 "2017-07-05T16:26:02Z")

</div>

Agreed! I was too focused on using timers! Thanks for the response.
