Part 7 : Gamemode

Back to main post

According to documentation: The GameMode object only exists on the server. It generally stores information related to the game that clients do not need to know explicitly. For example, if a game has special rules like “rocket launchers only”, the clients may not need to know this rule, but when randomly spawning weapons around the map, the server needs to know to pick only from the “rocket launcher” category.

Step 1 : Create Gamemode, Create Interface, Create reference to Gamemode.
Set your GameMode in your level.

Note : If you are following along with the different parts, you already made the gamemode at step 1 of part 6

create gamemode and interface
GameMode reference in interface
Connect Interface to GameMode and build Ref function
Set your GameMode in your Level. Set Default Pawn Class and PlayerControllerClass

I want to store the playerinfo of each connected player in the gamemode and want te be able to print all connected players to all clients. The GameMode knows which players are connected.
The problem is that the menu (widget) lives only on the clients and the gamemode lives only on the server. So I use the PlayerController (lives on both server and client) to communicatie between menu and gamemode.

Step 2 Blueprints GameMode
Add PrintConnectedPlayersGM to interface gamemode.
Add Event OnpostLogin in gamemode. Create var Connected Players.
Create array ConnectedPlayersInfo and fill with playerinfo of each connected controller.
Add Event OnLogout.
Add Event PrintConnectedPlayersGM which will print the player info on server and clients.

Add function PrintConnectedPlayersGM to interface gamemode
OnPostLogin add player to array
Fill array with playerinfo of each connected player controller.

Note: The ConnectedPlayers array is of type : Player Controller Object references! Turns out this is not my FD_PlayerController that is why you see the Cast to FD_PlayerController node.

Note: In part 6, step 3 the PlayerInfo from the GameInstance is copied to the PlayerController.

Event OnLogout
Event PrintConnectedPlayersGM

Note: PrintConnectedPlayersPC (prints on the clients) is discussed in the next step 3. player

Step 3 : Blueprints PlayerController
Event PrintConnectedPlayersPC (runs on Owning Client) prints the playerinfo of all connected players on the owning client
Event RunonServerGM (Run on server) which calls the PrintConnectedPlayersGM which is defined on the GameMode

Event PrintConnectedPlayersPC, which is called on the gamemode
Run PrintConnectedPlayersGM on Gamemode

Step 4 : MainMenu
Add button PrintConnectedPlayers to menu

Add button to menu (designer)
Run RunonServerGM on PlayerController

Video showing the result step 1 to 4

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.