How To Get some player info from all clients, store it on the server, then give a copy to all clients?

I have some sort of a lobby set and I want the players to be able to call the GameMode which has a list of all Player Controllers connected where the GameMode can then get the player info (struct) from all the Player Controllers, put it in an array, then give it back to all players so they can display the info on the HUD

I tried everything I could think of but I can’t get it to work, I only get the server’s Player Controller info over and over again. I’m sure that the Connected Player Controllers Array is set right and working, Sure that the Player Info is also set up properly, working and replicated

if you can provide example code as well, that would be generous of you as I’m still a beginner in networking

Hey ,

The GameMode is going to only exist on the server. You can send information from the GameMode to all of the clients but clients wont be able to access the GameMode; unless they have a server side version of the class, such as a PlayerController.

If you want to replicate something to all clients from the GameMode, you can try something like:

[MyGameMode.h]

UFUNCTION( server, reliable, WithValidation )
void ServerSendInfo( MyInfo *Info );

[MyGameMode.cpp]

bool AMyGameMode::ServerSendInfo_Validate( )
{
    // If you want to have a condition to be met in order for this to replicate, add here
    return true;
}

void AMyGameMode::ServerSendInfo_Implementation( MyInfo *Info )
{
     for( FConstPlayerControllerIterator Controller = GetWorld()->GetPlayerControllerIterator(); Controller; ++Controller)
     {
         AMyPlayerController *MyController = Cast<AMyPlayerController>( *Controller );
         if( MyController )
         {
              MyController->ClientRecieveInfo( Info );
         }
     }
}

[MyPlayerController.h]

UFUNCTION( client, reliable )
void ClientRecieveInfo( const MyInfo *Info );

MyInfo *LocalInfo;

[MyPlayerController.cpp]

void AMyPlayerController::ClientRecieveInfo_Implementation( const MyInfo* Info )
{
    LocalInfo = Info;
}