# Timer crashing UE4 C++

**URL:** <https://forums.unrealengine.com/t/timer-crashing-ue4-c/375998>\
**Category:** C++\
**Tags:** timers, unreal-engine, crash, question\
**Created:** [November 11, 2016, 4:02am UTC](https://forums.unrealengine.com/t/timer-crashing-ue4-c/375998 "2016-11-11T04:02:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Velvatrax](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Velvatrax](https://forums.unrealengine.com/u/Velvatrax)\
**Post date:** [November 11, 2016, 4:02am UTC](https://forums.unrealengine.com/t/timer-crashing-ue4-c/375998/1 "2016-11-11T04:02:42Z")

</div>

Hello everyone,

I making a lantern class that slowly uses fuel over time so I tried to setup a timer to handle fuel consumption. The Drain function decreases the fuel level of the Lantern. I am trying to make it so that the Drain function is called every 1 second. Thank you for your help, below is the code I am using to handle the timer. Any advice is appreciated!

```
ALantern::ALantern()
{
	PrimaryActorTick.bCanEverTick = true;
	Fuel_Level = 10000.0f;
	FTimerHandle Timer;
	GetWorldTimerManager().SetTimer(Timer, this, &ALantern::Drain, 1.0f, true, 3.0f);
}
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [November 11, 2016, 10:07pm UTC](https://forums.unrealengine.com/t/timer-crashing-ue4-c/375998/2 "2016-11-11T22:07:12Z")

</div>

Hello AndrewPrograhams,

It would be best if you were to set your timer elsewhere. Setting your timer in your constructor is a bad idea as it immediately starts the timer and calls any function it is set to call. This is what is causing the crash. Setting it in BeginPlay would be a good idea.

---

<div class="post-metadata">

**Author:** ![Velvatrax](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Velvatrax](https://forums.unrealengine.com/u/Velvatrax)\
**Post date:** [November 12, 2016, 12:03am UTC](https://forums.unrealengine.com/t/timer-crashing-ue4-c/375998/3 "2016-11-12T00:03:31Z")

</div>

Thank you so much!

---

<div class="post-metadata">

**Author:** ![Red-bear0025](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Red-bear0025](https://forums.unrealengine.com/u/Red-bear0025)\
**Post date:** [February 14, 2022, 4:01am UTC](https://forums.unrealengine.com/t/timer-crashing-ue4-c/375998/4 "2022-02-14T04:01:34Z")

</div>

thankyou so much I was freaking out my ue4 kept crashing on build
