I’m trying to create a lobby menu for a multiplayer game that uses Listen Servers.
The lobby includes a display for each connected player, with some information about their character.
I have an ALobbyPlayerState class that inherits from APlayerState and contains the character information.
The UI elements are controlled from each player’s ALobbyPlayerController, which inherits from APlayerController. In this class, I have a function RefreshPlayers, which tells the widget to update. The widget then loops through the GameState->PlayerArray and updates accordingly. RefreshPlayers is called from the AddPlayerState and RemovePlayerState functions of ALobbyGameState, which inherits from AGameStateBase. This successfully updates the number of players displayed.
However, when a player sets their character info to update their PlayerState, it is only updating locally. I’ve tried a few solutions to replicate it to other clients, but with no success.
Things I have tried:
-Put the character data into a replicated struct, then call the RefreshPlayers function on each player controller (fails as the OnRep function is never called, even when logging shows the value changes, GetLifetimeReplicatedProps sets it up, and the UPROPERTY and UFUNCTION macros are correctly set)
-Add a delegate to broadcast the change in the PlayerState, and listen for it in the GameState to call the update function (fails as the callback is never called, despite logging showing that the AddDynamic is called to set the delegate and the broadcast is called to trigger it)
-Use Server and NetMulticast functions in the PlayerState to replicate the change