When is it safe to access PlayerArray in GameState after a new Login to a multiplayer game?
Hey all! I am making a lobby for my multiplayer game. The lobby should show player names in two lists based on what team they are on. The host can start the game when they want or when the game is full. I'm running into an issue with updating my list of players. In my GameMode class I override PostLogin to add the new playercontroller to one of two teams located in my GameState class using a method called AddPlayerToTeam in the GameState class. The GameState method then calls a multicast function so that the host and all clients know that a new player has joined. This function simply broadcasts a multicast delegate. The UMG widget on each player has an overriden NativeConstruct method that adds a method to the multicast delegate in the GameState. This method updates the team lists now that the new player has joined. Below is the method that gets called when the UMG widget is constructed and when the multicast delegate mention above is broadcast.
The lists update correctly on my host. The first client to join the lobby doesn't see any players in either list. If a 2nd client joins, the 1st client's lists update and show the 1st client and the host. The 2ndd client shows itself on the list but neither the host or 1st client appear on the list. If a 3rd client joins, it behave similar to the 2nd client, but the 1st and 2nd clients will now see the host, the first client, and the 2nd client. While debugging, when I get to the for loop I pasted above, the PlayerArray doesn't seem to have been replicated yet. Does anyone have any advice? Or know a method that gets called when the PlayerArray is replicated that I can link to? It appears that I'm trying to update my list too early, before the client has received the list of other players.
TLDR: Trying to update a list of players on UMG widgets when a new player joins a game. PlayerArray isn't replicated in time. What can I do to ensure that the playerarray is updated so that I can update my list appropriately?
Follow this question
Once you sign in you will be able to subscribe for any updates here