TimerManager for Components?

Hello,

I’m having some issues with the TimerManager. I just can’t seem to get it work in my Actor Component, although whenever I tried the same thing in my character it works perfectly fine. Is there another syntax for timermanagers in components? If so, what is it? If not, how do I make myself some timers for my components?

Thanks in advance! :slight_smile:

~Stefan

Hello,

AFAIK timers should work correctly in components. Could you maybe provide some code of what it is you’re doing?

Either way I’m pretty sure the ActorComponent does not have a GetWorldTimerManager() function if that’s what you’re using in your character.

So I would suggest using either one of these to get the timer manager:

// Version 1 
FTimerManager Manager = GetWorld()->GetTimerManager();

// Version 2
FTimerManager Manager = GetOwner()->GetWorld()->GetTimerManager(); 

Ideally use the first one, but if that does not work the second one should. From the FTimerManager you can use the SetTimer(), ClearTimer() etc. functions.

~ Dennis “MazyModz” Andersson

This doesn’t work for me. Whenever I’m trying to GetOwner() i get an error saying “pointer to incomplete class not allowed”.

My previous code that I were using earlier, which I’ve now removed because it doesn’t work, is this:

	GetWorldTimerManager().SetTimer(TimerHandle_UpdateHealthRegenCooldown, this, &UHealthComponent::RegenHealth, 1.0f, true, 0.0f);

Thanks for helping, it’s appreciated! :slight_smile:

I’ve fixed my problem. I had to include “Actor.h” in order to GetOwner().
I did this by adding this include:

#include "GameFramework/Actor.h"

From there on I could use this syntax for setting a timer:

GetOwner()->GetWorldTimerManager().SetTimer(YourTimerHandle, this, &UMyComponent::MyFunction, 1.0f, true, 0.0f;