How to find number of players in a multiplayer game

Is there a way in blueprint to find out when a player has joined your game? there is a node called ‘get current players’ but I’m unsure how it should be used?

i want to maintain a variable of players i have currently in the game so i can know if its “game over”

You can, for example, count the Player Controllers on your server (only on the server because clients only know their own Controller).

Or you use the “Post Login” Event INSIDE the GameMode Blueprint. It’s called when a player sucessfully connected and it gives you it’s player controller:

http://puu.sh/flo6V/f7f56198e4.png

Or, i guess, you can work with PlayerStates :X But i don’t know about that.

thanks for the reply.
how would i count player controllers just on the server?

For example with “Get all actors of class” and select your controller class. Be sure to use this only on the server. Use a “switch has authority” node and put the logic behind the authority output.

Thank you very much for the reply

You can also poll for num players in the game at any time like this.

94313-untitled.png

If you are doing this on Steam the GetCurrentPlayers only works if you add the following config to the DefaultEngine.ini

[PacketHandlerComponents]

+Components=OnlineSubsystemSteam.SteamAuthComponentModuleInterface

How would i get this replicated into a widget so the client can see it?

GetGameState->PlayerArray.Num()

1 Like