Gamemode working separately for server/each client?

In an online game, when I’ve created 2 clients and one client created a session then another joined it, the ‘GetNumPlayer’ node from GameMode would not print 2, but instead, it prints 1 twice. The same applies when I’m getting the PlayerArray from GameState, as the length always return 1.

According to what I know for now, the whole game contains one instance. Each level contains one game mode only accessible from server, and each player contains a game/player state. Therefore, it’s supposed to return the correct values when I’m getting the variables from GameMode/GameState? Any idea of what I’ve done wrong here?

More info: I’m creating/finding sessions from BP by calling my C++ functions. They seem to work correctly as the players get to teleport to their designated maps. For fetching number of players, I’m doing such in BP. Either running dedicated server or not does not seem to affect the result above.

Hi, read this as a starting point for unreal classes in a multiplayer.

Thanks for the documentation. It would be better if there’s some direct pinpoint on where the problem’s exactly in.

I’ve read the documentation, and right now I know each game only has 1 game state accessible by client and server, while there are multiple player controllers.

So, an alternative I’ve tried is to create my ‘NumOfPlayers’ variable in GameState, and set it using player controller. However, when I print out the NumOfPlayers in runtime, the same still happens.

The printing result:

Server: 1

1

When there are supposed to be two players connected to the server. The 2nd player joins the session and level after the first player created and joined the session. Any more pinpoint is appreciated!

Update #1:

I’ve discovered that the NumOfPlayers can never by set to replicated when gotten from GameState in PlayerController. I’ve tried restarting the Unreal Editor and it still doesn’t work. I’ve also tried setting replication via class setting and it still doesn’t work? Does that contribute to why I’m not getting what I’ve intended?

Images:

The replication settings are only set in the class where the variable is, and it’s set to replicate. If a variable in bp has two spheres in the top right corner – then it is replicated.
Replication only occurs(as far as I know) from the server to the client, so if you set some value to the variable in the client it won’t be replicated. What you need to change it is to call RPC(remote procedure call) function and set authority to it. Info here.