GameState replication on listen server

Chorstikus
Mon, 21 Dec 2020 22:08:17 +0000
UI

Hey guys,

I have added an round variable to my GameState which gets replicated. After each kill it gets incremented and a multicast delegate event gets broadcasted.

Now in my HUD (UserWidget) I would like to show this round number. So within the NativeOnInitialized function I like to add AddDynamic on this dynamic multi-cast delegate. For some reason it works on the Client but not on the listen Server.

On the Server the GameState within the NativeOnInitialized is not valid or replicated yet. The Server goes into the else and logs “GameState not Ready”.

Any ideas on how to implement such a round timer in a userwidget?

void UWHUDWidget::NativeOnInitialized()
{
	Super::NativeOnInitialized();

	AWGameState* GameState = GetWorld()->GetGameState<AWGameState>();

	if (GameState)
	{
		UE_LOG(LogW_UI, Warning, TEXT("Binding UpdateRound Event"));
		GameState->OnNewRound.AddDynamic(this, &UWHUDWidget::UpdateRound);
	}
	else
	{
		UE_LOG(LogW_UI, Warning, TEXT("GameState not Ready"));
	}
}

7 posts - 1 participant