I can't use UObject method delegates with raw pointers

Hello,

I’m quite a newbie in C++ I agree with it… I have an error that I don’t really understand :

If I do this :

UWorld* World = whatever;

World->GetTimerManager().Whatever(this, &MyClass::MyFunction, ...);

It gives me : You cannot use UObject method delegates with raw pointers. on the second line.

What does that means ? Why can’t I do this ?

Thanks !

edit : This seems to occur because I try to set a timer from a non-UE class (it’s not an actor, not a blueprint, not a controller…), so how can I manipulate a “big global” timer from anywhere in the game like I’m trying to do ?

Hi Mystery,

I think what is happening here is that the function GetTimerManager() actually returns a reference not a pointer (denoted by the ‘&’ symbol). To call any function from the FTimerManager object which is returned from GetTimerManager() you need to use a ‘.’ indead of a ‘->’.

e.g.

UWorld* World = whatever;
World->GetTimerManager().Whatever();

When you have issues like these in the future be sure to take a look at the documentation at Unreal Engine 5.1 Documentation | Unreal Engine 5.1 Documentation to see what return types are given with functions you are trying to call. This documentation has help me heaps when i get issues like these.

Hope this helps your issue

#Code For You

is correct, you should be using . not →

And you should use GetWorldtimerManager() as long as you are in any Actor extending class.

Additionally here is a code sample to get you started with Timer in UE4, Enjoy!

void AYourClass::SomeFunction()
{
  GetWorldTimerManager().SetTimer(this, 
	&AYourClass::VictoryCheckAllThreadsDone, 1, false); //true for looping
}

void AYourClass::VictoryCheckAllThreadsDone()
{
	//do stuff 1 second after the above function is called
}
1 Like

Thanks for the answer. I have figured out what the problem is ; actually, I am trying to to create a timer from a class which extends nothing (not a BP, not an Actor…) and it appears that UE doesn’t like it. How can I create a “global” timer which is not depending on anything ? The goal is to create a thread working everywhere in the game (so as a static or global variable) ?

Thanks, I have answered on 's post, the problem is apparently not here :slight_smile:

My knowledge is limited as i’m still new to Unreal as well, but from what i see is you cant create a global timer which isn’t dependent on anything. Best guess is to use the World->GetTimerManager() (which is instantiated on game start) to get the FTimerManager which has several SetTimer functions. Im kinda assuming here as a “manager” it is able to handle more than one timer at a time.

FTimerManager | Unreal Engine Documentation for reference

This what I am trying to do here, passing a UWorld (or FTimerManager) as argument but this doesn’t seem to work =/

I have had the same problem, I just added the : public AActor to the header file. Now it complies.