GameState PlayerArray not in correct order

This is actually a pretty old problem that has plagued many a person trying to make a multiplayer lobby, scoreboard or just about anything else where players need to be in a consistent order.

Here is an example of the issue being raised almost two years ago. Back then an Epic staffer said that it is something that will hopefully be sorted (no pun intended) out in a future version… but almost two years?

There are ways around this of course, like storing your own ID per player state and sorting on that… or store your own array of players on the server and replicate it to the clients, which funnily enough, replicates in the correct order! I’ve noticed the later technique being used in Epic tutorial videos. But come on… why can UE4 replicate every other array in perfect order, but can’t get this one player state array in the correct order!

I couldn’t find this listed as a “bug” anywhere so I’m hoping we can enter a bug report for this long over due issue, unless there already is one that I can’t find.

Hey wilberolive,

I’ve attempted to reproduce the issue by printing the contents of the PlayerArray, but on my client and server I’m seeing the same results in the same order.

What steps are you taking on your end when you’re seeing the contents of the PlayerArray being stored in a different order?

Thanks

I’ve done some more testing in both 4.13.2 and 4.14.0. I’m testing both running in Selected Viewport and Standalone Game from the Play menu always with Number of Players set to 2 in the Play menu.

When using Standalone Game, I turn off Use Single Process and set Editor Multiplayer Mode to Play As Listen Server. When using Selected Viewport I turn Use Single Process back on.

The results are quite random. Sometimes the array will be in the correct order, but usually it is in the incorrect order. If it comes up in the correct order in one play mode, then usually if you run in the other Play mode and then go back again the order will be broken. Sometimes you can get a good run and they will come up in the correct order 3 or 4 times in a row, but then changing Play mode can put an end to the streak.

I have attached both projects. They will need to be compiled as they use a base C++ player state. I also tried converting the project over to be Blueprint only, just using the stock GameMode and PlayerState but they still came up in the wrong order.

Thanks for providing the project. I’m able to see the behavior now, and have entered a bug report, which you can track using the link below:

Thanks for your report.

Have a great day

Thanks Sean. Guess we now wait another 2 years :frowning:

I just noticed the bug report has been updated to “By Design.” What does that mean? That it is supposed to work like that? i.e. the array is supposed to be in a random order for each player? If so, that makes no sense.

I’ve updated the ticket with the reasoning for the decision that the issue was by design. Here is the explanation from our developers:

The array itself isn’t replicated. It just indirectly tracks the actors of type ‘APlayerState’ that are replicated. You could possibly sort the actors by player name or score in your implementation as a workaround. We don’t sort internally since we don’t know what the application would want to sort by.

Still makes no sense.

Firstly, we can’t sort that array as it populated by the engine. Therefore we have to maintain our own second array, just to keep a consistent play order.

Secondly, this player array is not meant to be sorted by player name or score or anything like that. The UI is responsible for that when it displays the list of players to the user.

The main point of this player array is to provide a consistent list of connected players. The order is irrelevant as long as it is consistent. They could just be in the order that they connected for example. In other words the server and all clients should be able reference player index 2 for example and get the same player.

I strongly believe this decision should be revaluated. It would hugely simplify building a multiplayer game as it would eliminate a lot of redundant and error prone code used to try and keep a consistent order. Take a look at some of the code that some epic devs have had to write themselves in tutorials and such to get around this problem.

I believe that “You could possibly sort the actors by player name or score in your implementation as a workaround.” was referring to creating your own array of actors that you could sort yourself rather than actually sorting the PlayerArray itself.

We appreciate your feedback; however, at this time, there are no plans to alter this behavior, as the developers are focusing their efforts on high-priority crash and showstopper bugs.