Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Can I use multiple timer handles on the same actor?

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?

Product Version: UE 4.8
more ▼

asked Jun 11 '15 at 08:28 PM in C++ Programming

avatar image

145 22 27 84

avatar image spazchicken Jun 11 '15 at 10:11 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Try doing this:

     FTimerDelegate::CreateLambda([this]() {
     }), processingTime, false

Using the above solution should get past the issue with FTimerManager::SetTimer 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** 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.

more ▼

answered Jun 11 '15 at 11:03 PM

avatar image

686 15 13 128

avatar image staticvoidlol Jun 12 '15 at 09:11 AM

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


 FTimerHandle FirstTimerHandle;
 FTimerHandle SecondTimerHandle;


     // 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);
     // Do stuff
     // Do stuff
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question