# Can I use multiple timer handles on the same actor?

**URL:** <https://forums.unrealengine.com/t/can-i-use-multiple-timer-handles-on-the-same-actor/321455>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [June 11, 2015, 8:28pm UTC](https://forums.unrealengine.com/t/can-i-use-multiple-timer-handles-on-the-same-actor/321455 "2015-06-11T20:28:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jechli\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jechli\_1](https://forums.unrealengine.com/u/jechli_1)\
**Post date:** [June 11, 2015, 8:28pm UTC](https://forums.unrealengine.com/t/can-i-use-multiple-timer-handles-on-the-same-actor/321455/1 "2015-06-11T20:28:09Z")

</div>

I currently have this code in a .cpp file:

```
pawn->GetWorldTimerManager().SetTimer(timerHandle, this, &UClass::TimerCallback, processingTime, false);

```

This is same code is being called from two different classes, but on the same actor (which I have called ‘pawn’ in this example). The timer handles are initialized in the two classes, with different names, as with the delegate functions. The difference is that this line of code runs fine in one class, but not in the other, despite using the SetTimer() function in the exact same way.

Given a processing time \> 0.0f, the first class delays for the proper amount of time before running the correct TimerCallback() function. The second class is given the same processing time, but it doesn’t delay nor run the TimerCallback() function. I’ve stepped through it and I _think_ it could be something to do with the timer handle not being initialized, though I can’t see why because I’ve initialized both timer handles the same way in both classes (actually, neither of them are ‘initialized’, they are simply declared in the .h file and I guess it’s initialized when I call SetTimer()…?).

Anyway, I just want to know why this is happening. Is it a conflict with the timers in the same actor? Or the fact that the delegate functions are from different classes? Or am I not properly using SetTimer, or initializing the Timer Handle properly?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_37c81313](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_37c81313](https://forums.unrealengine.com/u/anonymous_user_37c81313)\
**Post date:** [June 11, 2015, 10:11pm UTC](https://forums.unrealengine.com/t/can-i-use-multiple-timer-handles-on-the-same-actor/321455/2 "2015-06-11T22:11:46Z")

</div>

I personally have no idea, but you can just make your own timers too if you don’t get an answer 🙂

---

<div class="post-metadata">

**Author:** ![Zaucy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zaucy](https://forums.unrealengine.com/u/Zaucy)\
**Post date:** [June 11, 2015, 11:03pm UTC](https://forums.unrealengine.com/t/can-i-use-multiple-timer-handles-on-the-same-actor/321455/3 "2015-06-11T23:03:08Z")

</div>

Try doing this:

```
pawn->GetWorldTimerManager().SetTimer(timerHandle,
    FTimerDelegate::CreateLambda([this]() {
        TimerCallback();
    }), processingTime, false
);

```

Using the above solution should get past the issue with [FTimerManager::SetTimer](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/FTimerManager/SetTimer/4/index.html) specific overload feature being…

> If a timer is already set for this delegate, it will update the current timer to the new parameters and reset its elapsed time to 0.

Instead the code snippet I provided uses the overload of [FTimerManager::SetTimer](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/FTimerManager/SetTimer/6/index.html)\*\* that gets a generic delegate. This may not be best practice, however.

\*\* The example on this page seems to be incorrect. It doesn’t seem to be actually using the correct overloaded method.

---

<div class="post-metadata">

**Author:** ![staticvoidlol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@staticvoidlol](https://forums.unrealengine.com/u/staticvoidlol)\
**Post date:** [June 12, 2015, 9:11am UTC](https://forums.unrealengine.com/t/can-i-use-multiple-timer-handles-on-the-same-actor/321455/4 "2015-06-12T09:11:11Z")

</div>

I would think that declaring different handles would be a better solution, e.g.

Header:

```
FTimerHandle FirstTimerHandle;
FTimerHandle SecondTimerHandle;

```

Cpp:

```
AYourClass::SomeFunction()
{
	...
	
	// Start timer on first handle
	GetWorldTimerManager().SetTimer(FirstTimerHandle, this, &AYourClass::FunctionToCallViaFirstHandle, 5.0f);
	
	// Start timer on second handle
	GetWorldTimerManager().SetTimer(SecondTimerHandle, this, &AYourClass::FunctionToCallViaSecondHandle, 1.0f);

	...
}

AYourClass::FunctionToCallViaFirstHandle()
{
	// Do stuff
}

AYourClass::FunctionToCallViaSecondHandle()
{
	// Do stuff
}
```
