APlayerState::OnRep_Score
#include "GameFramework/PlayerState.h"
Access: public
Specifiers: virtualUFUNCTION
Description
Replication notification called on clients when the Score property changes on the server. Override to react to score changes on the receiving client, such as updating a local scoreboard widget.
Caveats & Gotchas
- • This is only called on clients (or the listen-server for non-owning connections). It is never called on a dedicated server. Authority-side logic should go in SetScore() or wherever score is modified.
- • The engine calls this after Score has already been updated to the new value. You can read GetScore() inside the override, but there is no built-in access to the previous value — cache it yourself if you need a delta.
- • The base APlayerState implementation of OnRep_Score is empty. Calling Super::OnRep_Score() is a no-op but is still recommended for forward-compatibility with future engine changes.
Signature
ENGINE_API virtual void OnRep_Score(); Return Type
void Example
Refresh scoreboard widget when score replicates C++
void AMyPlayerState::OnRep_Score()
{
Super::OnRep_Score();
if (APlayerController* PC = GetWorld()->GetFirstPlayerController())
{
if (AMyHUD* HUD = Cast<AMyHUD>(PC->GetHUD()))
{
HUD->RefreshScoreboard();
}
}
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?