# Why is the timer not calling the function?

I am trying to call a function every 30 seconds. I have used this before without issues so I'm not sure why it isn't working now. Any ideas? Has something changed in 4.24 maybe?

.h I have tried both public and private

UFUNCTION()
void Ping();


And the .cpp I see both logs in the output so I know its getting there. Also the ensure passes. I have also tried GetWorld which is null in a UObject and GWorld which also works but has the same problem of the ping function not being called at all.

UE_LOG(LogTemp, Warning, TEXT("start ping"))
if (ensure(GEngine))
{
UWorld* World = GEngine->GetWorldContexts()[0].World();
UE_LOG(LogTemp, Warning, TEXT("start ping has gworld"))
World->GetTimerManager().SetTimer(PingTimerHandle, this, &UGameJoltApi::Ping, 30, true, 30);
}


And here is the ping function. Its not called even once. I never see the log in the output.

UE_LOG(LogTemp, Warning, TEXT("ping"))
FString Url = URLBaseApi + URLSessions + "ping/?game_id=460364&username=" + Username + "&user_token=" + UserToken;

TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
Request->SetVerb("POST");
Request->SetHeader("Content-Type", "application/json");
Request->SetURL(GenerateUrl(Url));
Request->OnProcessRequestComplete().BindUObject(this, &UGameJoltApi::OnStartSessionResponse);
Request->ProcessRequest();

• Probably the world you get from GEngine is not the one currently in play. Can your UObject implement GetWorld by referencing its Outer? Feb 2, 2020 at 20:02
• There isn't an outer AActor. Its just a lone UObject. I changed it to extend AInfo docs.unrealengine.com/en-US/API/Runtime/Engine/GameFramework/… so its an AActor and tried GetWorld() and the function still is never called. Feb 3, 2020 at 3:59
• You dont have ‘;’ after the UE_Log - but that probably unrelated Feb 3, 2020 at 10:34
• Also you have an initial delay of 30 secs - did you wait these 30 secs ? I would advice to remove the initial delay for the ease of debugging. Feb 3, 2020 at 10:36

## 1 Answer

I havent found an answer but I found a workaround. I moved the code in the UObject that starts the timer to my GameInstance and everything works as it should. I have no idea why I couldn't do this in the UObject but this is probably better design wise anyway as the API shouldn't have to worry about timers and such.

• This is very strange - I have plenty o timers in UObjects - and they always worked :-| Feb 5, 2020 at 0:05
• It is strange. I've never had problems with this before either. I'm curious if this is a change in behavior in 4.24. Feb 6, 2020 at 11:22