I am having some issues wrapping my head around replication.
I have a lobby level that has a 3d Widget in there that i would like to display some information for each pc connected to the server.
I want all this info to come from the server.
So I created a GameMode and GameState
Using the following code for the game state.
UCLASS()
class ALLSPARK_API AAllSparkGameState : public AGameState
{
GENERATED_BODY()
public:
UFUNCTION(Reliable, Server, WithValidation, BlueprintCallable, Category = "GameState")
void UpdateConnectedPCs();
void UpdateConnectedPCs_Implementation();
bool UpdateConnectedPCs_Validate();
UFUNCTION(BlueprintPure, Category = "GameState")
TArray<APlayerController*> GetConnectedPCs() const;
private:
TArray<APlayerController*> ConnectedPCs;
};
TArray<APlayerController*> AAllSparkGameState::GetConnectedPCs() const {
return ConnectedPCs;
}
void AAllSparkGameState::UpdateConnectedPCs_Implementation() {
if (Role == ROLE_Authority)
{
for (auto allPCs = GetWorld()->GetPlayerControllerIterator(); allPCs; ++allPCs)
{
bool found = false;
auto CurrentPC = Cast<APlayerController>((*allPCs));
if (CurrentPC)
{
for (auto inArray(ConnectedPCs.CreateIterator()); inArray; inArray++)
{
auto inArrayPC = Cast<APlayerController>((*inArray));
if (inArrayPC == CurrentPC) {
found = true;
}
}
if (found == false) {
ConnectedPCs.Add(CurrentPC);
}
}
}
}
}
bool AAllSparkGameState::UpdateConnectedPCs_Validate() {
return true;
}
This all works fine for the server but the clients are getting nothing in the array.
Can anyone see what i’m doing wrong its probably real obvious :S