mercredi 6 janvier 2016

ue4 : networking day1

The aim of my game is to do a multiplayer game, with a dedicated server and clients.

It was sometimes hard to find my way, to understand networking in unreal engine, so I will try to take time to explain different things about networking, and to illustrate what I 've done in my game about the different topic.

If you need, more precise focus, let me know.

First of all, because it is dedicated server, server has control over all things. You have to draw blueprint in same blueprint for case of "server", and case of "client".

It is important to understand this. It is important also to understand what will be managed by server and replicated to client, and what is manage by client.

On client board, you will manage essentially UI, special effects, keyboard/mouse input management...
Server will manage AI, movement, physics, spawning, ...

So every time, you wish to move your pawn, through keyboard input, you will have to send the information to server, which will move the pawn, and replicate/broadcast new position.

Ok with this very few basics...

First, I will show you how to manage increase/decrease speed on my spaceship.
First I create new input in project settings








 Next in my pawn Blueprint, I create two variables, speed, and speedmax.
Speed will be replicated. It is an information needed by client to manage UI and FX for example.
Replication is always from server to client.



I ve created next a new custom event in my blueprint. The event receives the new speed, and set the variable with it.
Event must be run on server



 Finally, I receive my speed input (through A or W keyboard input), and I manage the increase of speed, and send it to server.





Pay Attention on switch authority. Switch authority allows to run what is after on server, or client. Here, because it is a client input, I have to manage following on client. So I choose remote.
If it was an event about collision for example, I must switch on authority, to manage it only on server.

If you don't use this switch, it will be run on both (client and server), and you can have strange behavior or maybe error. For example, if you manage to update an UI, on dedicated server, you will have errors, because there is no window for server.

Here, you will manage keyboard input to increase speed, and send the update to server.
Server will update speed variable, and because of that, the update will be replicated to all client.

To do better, you can send the input to server, which will manage the different test case, to be sure and guarantee no cheat :D


























Aucun commentaire:

Enregistrer un commentaire