Effiecent Way of Updating Player List

Since I’ve finally got my lobby system to work with Steam*(albeit only with European clients)*, I’m now working on refactoring stuff. Currently, I’m updating the player list via using the array of players stored in the gamestate. I’m doing this every second, and while it works - it does result in a lagspike every second.

Simply what I’m doing is recreating the player list every second. I clear it, rebuild it - I know it’s a lousy way of doing things but it worked for basic testing. This includes getting their player name and Steam avatar*(thanks to Mordentrals awesome plugin!)*.

What confuses me is how I would go about to make events instead, every time someone either joins or leaves the session. One method I had in mind was to store the player array upon widget construct, and simply check the size every second instead to see if it’s larger or smaller and if a change is found - compare the old array to the new to find what’s changed.

But I’m afraid I’ll run into issues because people might join and leave at around the same time. If anyone has any suggestions of a better approach I’d greatly appreciate it!


Worth noting that I can not create my own GameState, whenever I do - I can never access the player array. I’ve no idea if this is intended behaviour or a bug.

GameMode provides you with those events.
PostLogin and Logout, they return playercontroller so you might need to work around that.

Aye, I’m aware of those events - but I think I may need to do some redesigning to make it work. Will investigate this tomorrow! :slight_smile:

Uh I also was digging in this stuff and I think that without C++ this will be just messy. Multiplayer (sessions) are very basic in blueprints, there is one plugin (advanced sessions).
Because of all those problems (and very high possibility of major changes to multiplayer) I am leaving steam integration for last step.

Epic also promised steam multiplayer and services tutorial, its still not there.

I am brainstorming here (I did not tested this), but there is “Player State” blueprint, it is replicated lightweight copy of player controller, that copy is allocated on server and EVERY client has its own replicated copy.
There is also that advanced session plugin it gives unique IDs about every player in session. So my idea is to loop trough all player states ask them about network ID and compare to stored array.

I’ve been playing around with this a bit today, and while the GameMode events are exactly what I want - they’re rendered useless simply due to the fact we can not trigger client-side events from the GameMode.

I need to get all widgets in order to get access to the function that generates the player list. Obviously, this would only work for the host if I were to do it in the GM. Basically this is what I tried;

1. I created a custom PlayerController, which has a custom event; Client_TestOutput - outputs a simple “Hello”.
2. In the GameMode, everytime someone logs in - I add their PC to an array.
3. After it’s been added, I loop through this array - casting it to my custom PC in order to execute the Client_TestOutput event.
4. Due to the way GM works, the server will output the message - despite the event being client-sided inside my custom PlayerController.

In other words I’ll see “Server: Hello” multiple times, instead of once and the others being “Client #: Hello”.

This is where I start scratching my head as it violates all my previous experience with Client/Server interaction.

One theory I have is that I could possibly achieve what I want if I make a custom PlayerState and have the event in there instead, but everytime I’ve made a custom PlayerState or GameState - something always breaks and stops working. If I make a custom GameState, it will always fail to retrieve the PlayerArray. If I make a custom PlayerState, it will always fail at getting the PlayerName.

I guess I’ll stick with the method I’m currently using which just checks the size of the PlayerArray inside GameState every second(might simply just have to reduce the delay). I was hoping to be able to use the GM events but alas, we can’t have everything served on a silver platter. :rolleyes:


With the current method I was able to reduce the delay to 100ms without any noticeable performance loss. Now I just gotta find a way to make sure they’re listed in the same order. A real shame the PlayerArray is differently indexed every time you fetch it :frowning: