Pure Diamond! Really thank you for putting up such a great documentation! Fluent sentences and all those graphics really help to enjoy learning about this part of the engine. Absolutely awesome!
Gnah, repay me by telling me if it’s helpful or not and what could be changed, added or left out for the next one. (:
Also by notifying me if you find mistakes or false information!
i have a question about slide N°20, you said “PlayerArray” variable is replicated and have sense because is an array of PlayerState class but why it not have the two small circles like others replicated variables? Could be not immediate understand is replicated if you don’t go into GameState and PlayerState class definition.
I should have been more clear about that.
The Variable is NOT replicated, but since the PlayerState is replicated, it can fill ITSELF into the the Array on all Clients. Probably doing this in “PostInitializeComponents”. So the client version of a PlayerState adds itself to the Clients PlayerArray.
I will alter/add this information.
Cheers!
EDIT:
Until I find time to add this information, is the Part INSIDE of the PlayerState, that manages adding itself to the PlayerArray:
void APlayerState::PostInitializeComponents()
{
Super::PostInitializeComponents();
UWorld* World = GetWorld();
// register this PlayerState with the game's ReplicationInfo
if ( World->GameState != NULL )
{
World->GameState->AddPlayerState(this);
}
.....
}
PostInitializeComponents is called on all instances of the PlayerState. So on the Server and on the Client Versions. So every instance adds itself to the GameState’s PlayerArray.
You could also do this only on the Server and replicated the Array, but why wasting bandwidth? (:
The GameState itself also gathers all PlayerState, for the case there were already some PlayerStates and the GameState wasn’t ready yet:
Of course, this is being a “Unique” Add, so no duplicated entries. The “AddPlayerState” function has the following implementation:
void AGameState::AddPlayerState(APlayerState* PlayerState)
{
// Determine whether it should go in the active or inactive list
if (!PlayerState->bIsInactive)
{
// make sure no duplicates
PlayerArray.AddUnique(PlayerState);
}
}