The client wants to obtain the status of all players who have joined the current game, so I created AMyGameState to inherit AGameStateBase, rewrite the AddPlayerState (APlayerState* PlayerState)
function, and naturally call PlayerState->GetPlayerName()
inside to read the player’s name, but I didn’t get anything! The variables in PlayerState
are mostly 0 or empty.
After debugging, I found that the OnRep_PlayerName()
function of APlayerState is required to read the player’s name. So, please UnrealEngine change the calling process and trigger AddPlayerState(APlayerState* PlayerState)
at least after all variables in PlayerState have completed the first copy. This is in line with normal thinking logic.