RealDocs

APlayerState::SetScore

function Engine Since 4.0
#include "GameFramework/PlayerState.h"
Access: public Specifiers: ENGINE_API

Description

Sets the player's score and triggers replication to all clients via OnRep_Score.

Caveats & Gotchas

  • Must be called on the server (authority) — calling from a client has no networked effect and the value will be overwritten on the next replication update.
  • Does not clamp or validate the value; negative scores are valid and it is the game's responsibility to enforce any minimum/maximum constraints.

Signature

void SetScore(const float NewScore)

Parameters

Name Type Description Default
NewScore const float The new score value to assign.

Return Type

void

Example

Award points on server when player scores a goal C++
void AMyGameMode::OnGoalScored(AController* ScoringPlayer)
{
    if (APlayerState* PS = ScoringPlayer->PlayerState)
    {
        PS->SetScore(PS->GetScore() + 1.0f);
    }
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.