How can I change the max number of players per server?

Hey! So, basically, I’m prototyping a multiplayer game and I copied all my network stuff from the “multiplayer shootout” example. It is pretty well crafted and it works wonders with my level.
Only problem is, I can’t seem to be able to change the “max players” int variable, blueprints has a function that can only “get” it from the “AGamesession” class.
Also it looks like to be in the “global config” but the documentation does not say much.

  • I cannot set it from the blueprint
  • I cannot find the original class containing the script
  • I have changed every single “maxplayers” value in the game project folder files
  • I have time and determination!

I have the feeling that this is something really silly, but without the proper knowledge I just can do it, but at the same time I am pretty sure most devs had to do it at least once.

These pictures explain quickly what I did 'til now and how it didn’t work.

Hi Snowbro,

You should be able to change the “Public Connections” parameter of the Create Session Blueprint node. This value in the online session is independent of the engine’s MaxPlayers config value for the GameSession, in most cases both values should be set to the same thing.

Note that currently the Null online subsystem doesn’t enforce the “Public Connections” value, but the MaxPlayers setting will still be enforced at the engine level. The Steam online subsystem should enforce Public Connections, though.

10/10
I love you

Ryan,

I’ve got my game working with a server list and a click to join.
It shows current and max players. When its maxed… other players can still join.

I have different game scenarios. like 2v2, 1v1 …
so is there a way to enforce the max connections? I can’t hard set it in the game because sometimes I need to allow 4 or 2 or 8 etc…know what I mean?

Use different game modes, or use bools to determine which type of settings will be used at Match Creation.

In general you set this via the ‘MaxPlayers’ configuration parameter, which you’ll find in:

Config/*Game.ini

(either Engine/Config/BaseGame.ini, or Config/DefaultGame.ini)

Look for a section like so:

[/Script/Engine.GameSession]
MaxPlayers=16

So by searching Ive found out that GameSession will only check MaxNumberOfPlayers if its not a Standalone game.

The only way I`ve been able to fix it is by overriding PreLogin at AGameStateBase and adding my own check for max number of players. (currently I’m just using a constant)

	if (GetNumPlayers() >= 4)
	{
		ErrorMessage = TEXT("Server full.");
		FGameModeEvents::GameModePreLoginEvent.Broadcast(this, UniqueId, ErrorMessage);
		return;
	}
	
	Super::PreLogin(Options, Address, UniqueId, ErrorMessage);
1 Like

Hi, Saishy. In your way, it will not work if many players try to join game at same time. Because GetNumPlayers() function will add new player after post login, but this gap need time.
Do you have better way now?