# Correct use of timers?

**URL:** <https://forums.unrealengine.com/t/correct-use-of-timers/353850>\
**Category:** C++\
**Tags:** timers, unreal-engine, CPP, question\
**Created:** [April 12, 2016, 5:14am UTC](https://forums.unrealengine.com/t/correct-use-of-timers/353850 "2016-04-12T05:14:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![giorgk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@giorgk](https://forums.unrealengine.com/u/giorgk)\
**Post date:** [April 12, 2016, 5:14am UTC](https://forums.unrealengine.com/t/correct-use-of-timers/353850/1 "2016-04-12T05:14:30Z")

</div>

Hi I’m trying to write a simple timer that I can start, pause and and stop anytime. At the moment I have’t figured out all the details about timers and this is how I have done so far:

I have defined the following in the header file:

```
FTimerHandle MyGameTimer;
float mytime = 0.0f;
void update_timer();
float time_increment = 0.01f;

```

At the begin play method I set:

```
GetWorldTimerManager().SetTimer(MyGameTimer,this,&AMyGameMode::update_timer, time_increment, true);

```

while the update\_timer method does the following:

```
void AMyGameMode::update_timer() {
	mytime = mytime + time_increment;
}

```

This seems to work but I was wondering if this is a proper way to do such a simple task.

Thank you

---

<div class="post-metadata">

**Author:** ![ryanjon2040](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ryanjon2040/32/906587_2.png) [@ryanjon2040](https://forums.unrealengine.com/u/ryanjon2040)\
**Post date:** [April 12, 2016, 5:21am UTC](https://forums.unrealengine.com/t/correct-use-of-timers/353850/2 "2016-04-12T05:21:56Z")

</div>

Yes this is the correct use of Timers. One small suggestion from me is to replace the below line

```
mytime = mytime + time_increment;

```

with

```
mytime += time_increment;

```

Both does the same job but second one is much more simpler IMHO. 🙂

---

<div class="post-metadata">

**Author:** ![giorgk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@giorgk](https://forums.unrealengine.com/u/giorgk)\
**Post date:** [April 12, 2016, 6:00am UTC](https://forums.unrealengine.com/t/correct-use-of-timers/353850/3 "2016-04-12T06:00:39Z")

</div>

thank you!
