RealDocs

APlayerState::GetStartTime

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

Description

Returns the game time in seconds at which this player joined the session. Useful for computing how long a player has been in-game.

Caveats & Gotchas

  • The value is in integer seconds and is set by the server when the player joins. It reflects world time (GetWorld()->TimeSeconds cast to int32), not wall-clock time.
  • On listen servers and clients the value is replicated from authority, so there can be a brief window after join where it reads 0 until the first replication update arrives.

Signature

int32 GetStartTime() const

Return Type

int32

Example

Calculate time spent in session C++
int32 JoinTime = PlayerState->GetStartTime();
float SessionDuration = GetWorld()->TimeSeconds - (float)JoinTime;
UE_LOG(LogGame, Log, TEXT("Player has been in session for %.1f seconds"), SessionDuration);

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.