Making Multiplayer

I have been trying to learn how to make a multiplayer game on Unreal using blueprints, does anyone knows a place where I can found detailed and well explained tutorials and information about the subject? I’m currently trying to understand the best way to work the communication between client and server, It’s best to make everything happens on server and then just replicate to clients right? The player controller represents the client, and the game state the server? I once read that the less you let the client do things on its own, harder it is to hack or cheat on the game, is this true? If so, how do I make this happen if the player controller can’t cast to game mode? Maybe use the replication type of custom events? If I choose to replicate the event from server to clients (multicast), even if the event itself is on the player controller, I’m I protecting the game from hackers? On the multicast type of replication what does it means that the server will execute the event locally too, isn’t the server only hosting the game? Whats does the “Reliable” bool does? I’ve been testing some stuff, and when I run the game on editor, running a dedicated server, with more than one player, it seems to only spawn one player controller, I mean I can only see one on the world Outliner , even thought multiple player states appear, shouldn’t also appear one player controller for each player? For dedicated server based multiplayer games to work, the server will be running all the time, how do I make this happen when the game is complete? How do I define what is the server and what is the client, so that I can execute the server on my server machine, and let it running, and then distribute only the client to the players? How to make a lobby for player looking for a match wait for the minimum amount of players required?

Any other tips or things that I should know?

Super thank you for anyone willing to answer any of this questions, even that just one, I know it’s a lot to ask, but you have no ideia how helpful it would be for you to share just a little bit of your knowledge!

That is a lot of questions.

It’s best to make everything happens on server and then just replicate to clients right?

When possible yes.

The player controller represents the client, and the game state the server?

Yes the player controller represents a client. It works exactly like a console controller giving the client a way to send input “privately” to the server without interference from other players. The server can also privately send information back to the individual clients.

The Game State is where the server communicates events to all clients mostly originating from the GameMode which only exists on the server.

I once read that the less you let the client do things on its own, harder it is to hack or cheat on the game, is this true?

Yes every time you allow a client to do something on the server the server has to validate that the client isn’t trying to cheat, however avoiding cheaters can only be done when you deploy a dedicated server since you can’t trust a player host.

If so, how do I make this happen if the player controller can’t cast to game mode?

Server-side PlayerController can “get” and cast to the GameMode but GameMode should only be used for changes within the overall state of the game. Validation can happen anywhere server-side.

If I choose to replicate the event from server to clients (multicast), even if the event itself is on the player controller, I’m I protecting the game from hackers?

No. Protection from hackers is purely done by the server validating the input from the clients. If the input doesn’t make sense the server can decide to kick the player. Note that a Multicast RPC on a PlayerController is pointless since each client only have access to their own PlayerController.

On the multicast type of replication what does it means that the server will execute the event locally too, isn’t the server only hosting the game?

Yes the server is hosting the game which means it is keeping track of everything to keep itself updated. A dedicated server doesn’t of course run any graphical, audio or input events, it just serves the clients.

Whats does the “Reliable” bool does?

If an event never reaches the client (if Multicast) and it is set to reliable it will retry until the client gets the event. Before you go and make every event Reliable just note that a lot of events can safely be dropped to help the server recover from network congestion. If you make everything Reliable nothing can be dropped and the network congestion could get a lot worse and frequent.

I’ve been testing some stuff, and when I run the game on editor, running a dedicated server, with more than one player, it seems to only spawn one player controller, I mean I can only see one on the world Outliner , even thought multiple player states appear, shouldn’t also appear one player controller for each player?

Each client only see their own PlayerController. The server see all PlayerControllers. If you make a Multicast RPC on a PlayerController only the owning client will get the event.

How do I define what is the server and what is the client, so that I can execute the server on my server machine, and let it running, and then distribute only the client to the players?

You need the source code from github and build the editor first using Visual Studio or something else. You can’t build a dedicated server or client only with an installed engine and Blueprint. Then you can package a dedicated server and a client build separately.

How to make a lobby for player looking for a match wait for the minimum amount of players required?

This can be done by 3. party plugins like Steam where a Matchmaking server is responsible for handling lobbies and/or matching players. The plugin then returns a server/host IP and Port for the players to join.

Any other tips or things that I should know?

Making a multiplayer game is harder than you might initially think. If you have made a single player game you can probably multiply the difficulty of every feature you develop by 5 when making it multiplayer. Guessing how things work is the road to disaster, you need to make a deep dive into how things actually work or you will be debugging your life away.

No worries I enjoy answering multiplayer questions. I am currently working on a smaller multiplayer game and it has a fair amount of challenges. The reward of making a game multiplayer is worth it but it definitely is a challenge in the beginning.

WOW, you absolutely nailed it, thank you, thank you and thank you! I know it must have taken you some time to answer everything so I really appreciate that, sorry for the amount of questions, and thank you again. Maybe just one more, :), have you ever made a multiplayer game? If so, how did it ended up? I don’t actually wan’t to make I real multiplayer game, I prefer singleplayer games, play them a lot more, and want to develop them a lot more, I just like to learn things, so I just want do actually know how a multiplayer game is made, to a certain degree at least. And thank you again, you’re the boss!!!

Hey, when you have some youtube videos about it, or when you launch it, I would love to see how it looks, best of luck on your developments!!

Thanks a lot :slight_smile: