Download

Can somebody give me some clearance on timers? C++

Ok so i read this docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Timers/index.html
and i find it very overwhelming compared to a simple tick timer and when i try to test some of this
code i get warnings and errors and nothing works?

Could somebody please give me so clearance/basics on how to create a simple timer and how to stop said timer etc, or
describe to me how it works? Thanks. :slight_smile:

That’s outdated, unfortunately. In 4.7 timers changed a lil bit.

Now you must declare an FTimerHandle object. Name it whatever you want.

	FTimerHandle Whatever;

Then get the game world, get the world’s timer manager, then call SetTimer(). SetTimer() has a number of overloads, but the simplest one in my opinion takes the FTimerHandle you just declared, the object that will contain the timer (in this case, the calling object), a reference to the method you want to call (as a delegate), the number of seconds to wait between each call, (optionally) whether or not it should call the method over and over again (defaults to false) and (optionally) how many seconds the Timer should wait before starting.

	GetWorld()->GetTimerManager().SetTimer(Whatever, this, &MyObject::TheMethodIWannaCall, 5.f, true);

So here I want to send a message to this object that says “Call TheMethodIWannaCall() every 5 seconds and do it over and over again every five seconds after that.” I left out the last parameter because I don’t want the Timer to wait any longer before waiting the first five seconds. You can leave out the second-to-last parameter if you don’t want to loop.

The Timer Handle system is much nicer though, way more streamlined and makes more sense.

There’s also a few overloaded versions of the SetTimer() function, if you have Visual Assist installed, hover over it to find them.

Thank you, soo much! this help me a lot, even better with code samples!
I got my basic timer working :slight_smile:

I’m glad it worked out! Timers are super useful.

I had timers working on 4.6 on a SCompoundWidget extending the Editor to poll an array of objects for updates (filled by another Thread). I suppose this isn’t working anymore? Any workarounds for 4.7 on this?
My timer function is never called since the update ;-(



MyDelegate = FTimerDelegate::CreateSP(this, &MyImportScreen::UpdateTimer);
World->GetTimerManager().SetTimer(TimerHandle, MyDelegate, 2.0f, true);


(I think I have fixed it into oblivion, but this should be the working part on 4.6)