Hello,
I’m actually trying to get some global functionality in c++ that I want to run once per tick. Unfortunately, GameInstance does not have a tick or even a beginplay. So, Is there any way to make a global tick in c++?
Hello,
I’m actually trying to get some global functionality in c++ that I want to run once per tick. Unfortunately, GameInstance does not have a tick or even a beginplay. So, Is there any way to make a global tick in c++?
One way: Spawn an actor and save a reference to it in your GameInstance. Implement your tick functionality in that actor.
Ok Thanks, I think I’ll do that on the BeginPlay of a Custom GameMode.
Maybe this can help you
FDelegateHandle TickDelegateHandle;
void UGameGlobal::Init()
{
// Register delegate for ticker callback
TickDelegateHandle = FTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateUObject(this, &UGameGlobal::Tick));
Super::Init();
}
void UGameGlobal::Shutdown()
{
// Remove delegate for ticker callback
FTicker::GetCoreTicker().RemoveTicker(TickDelegateHandle);
Super::Shutdown();
}
bool UGameGlobal::Tick(float DeltaSeconds)
{
return true;
}
I would implement this functionality using a looping timer in a custom subclass of UGameInstance
or in an UActorComponent
added to a custom AGameModeBase
.
oh