I tried to create a Delegate in PlayerState and use it by binding to the Delegate in PlayerState in HUD.
// Below is the PlayerState code. HUD tries to bind to Fuc_Dele_UpdateHp_OneParam.
void AShootingPlayerState::OnRep_CurrentHealth()
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow,
FString::Printf(TEXT(“UpdateHp CurrentHealth=%f”), GetCurrentHealth()));
if(Fuc_Dele_UpdateHp.IsBound())
Fuc_Dele_UpdateHp.ExecuteIfBound();
if (Fuc_Dele_UpdateHp_OneParam.IsBound())
{
Fuc_Dele_UpdateHp_OneParam.ExecuteIfBound(GetCurrentHealth());
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow,
FString::Printf(TEXT("None Bound Fuc_Dele_UpdateHp_OneParam!")));
}
}
// Below is the HUD code.
// Bind is attempted by calling the BindPlayerState function in BeginPlay. By making this a // recursive function, I am trying until PlayerController and PlayerState are valid.
void AShootingGameHUD::BeginPlay()
{
check(HudWidgetClass);
HudWidget = CreateWidget<UUserWidget>(GetWorld(), HudWidgetClass);
HudWidget->AddToViewport();
FTimerManager& timerManager = GetWorld()->GetTimerManager();
timerManager.SetTimer(th_BindPlayerState, this, &AShootingGameHUD::BindPlayerState, 0.1f, false);
}
void AShootingGameHUD::BindPlayerState()
{
//GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow,
// TEXT(“Try BindPlayerState”));
APlayerController* pc = GetWorld()->GetFirstPlayerController();
if (IsValid(pc))
{
AShootingPlayerState* ps = Cast(pc->PlayerState);
if (IsValid(ps))
{
ps->Fuc_Dele_UpdateHp_OneParam.BindUFunction(this, FName(“OnUpdateMyDamage”));
OnUpdateMyDamage(ps->GetCurrentHealth());
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow,
FString::Printf(TEXT("%d Complate BindPlayerState"), *ps->GetName()));
return;
}
}
FTimerManager& timerManager = GetWorld()->GetTimerManager();
timerManager.SetTimer(th_BindPlayerState, this, &AShootingGameHUD::BindPlayerState, 0.1f, false);
}
There were no errors.
The server is fine.
Here’s an issue where in multiplayer, the client info didn’t apply to the UI.
“TimerManager.SetTimer(th_BindPlayerState, this, AShootingGameHUD::BindPlayerState, 0.1f, false);” in “BeginPlay”
Changing the time to “1.0f” in this timer code solved it fine.
Here, the conclusion is that “IsValid” alone is not enough to make a bindable check.
Is there a way to perfectly check if a bind is possible?