Here is a solution :
.h :
UCLASS()
class MYPROJECT_API UMyObject : public UObject, public FTickableGameObject
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = Test)
void CallTimer();
void TestTimer();
void Tick(float DeltaTime) override;
bool IsTickable() const override;
bool IsTickableInEditor() const override;
bool IsTickableWhenPaused() const override;
TStatId GetStatId() const override;
UWorld* GetWorld() const override;
float TestCounter;
};
.cpp
void UMyObject::CallTimer()
{
FTimerHandle tHandle;
const float Delay = 1.0f;
GetWorld()->GetTimerManager().SetTimer(tHandle, this, &UMyObject::TestTimer, Delay, false);
}
void UMyObject::TestTimer()
{
GEngine->AddOnScreenDebugMessage(1, 2, FColor::Red, "Hello World");
}
void UMyObject::Tick(float DeltaTime)
{
TestCounter += DeltaTime;
GEngine->AddOnScreenDebugMessage(0, 0, FColor::Green, FString::SanitizeFloat(TestCounter));
}
bool UMyObject::IsTickable() const
{
return true;
}
bool UMyObject::IsTickableInEditor() const
{
return false;
}
bool UMyObject::IsTickableWhenPaused() const
{
return false;
}
TStatId UMyObject::GetStatId() const
{
return TStatId();
}
UWorld* UMyObject::GetWorld() const
{
return GetOuter()->GetWorld();
}