I’m building an RTS game in which the PlayerController is responsible for nothing more than camera movement and relaying input commands to the player’s units (ACharacters controlled by AAIControllers). The system I initially envisioned was to have the client PlayerControllers store references to the Characters, which would then give access to the AIControllers. I tried setting up the spawning and reference storing like this:
void ABasePlayerController::BeginPlay()
{
OwnedCharacters.Add(GetWorld()->SpawnActor<ABaseCharacter>(/* Spawn params */);
if (OwnedCharacters[0]) // OwnedCharacters is a TArray of all of the player's units
{
OwnedCharacters[0]->SpawnDefaultController();
CurrentCharacter = OwnedCharacters[0]; // CurrentCharacter is the currently selected character
}
}
While this works fine for singleplayer and the server, OwnedCharacters and CurrentCharacter are NULL for clients. I feel like this is a fairly simple replication problem, but I’m new to the replication system in UE4. What can I do to get a reference of the characters and their controllers to clients? Or should I be going about this in a different way? Thanks!