Help Understanding Replication
Not sure if this has been asked before, so I apologize if its re-occuring. I understand how replication works and when its necessary very much so, but I am having trouble understanding why certain variables or info on the client cant be sent to the server, and why things created on the server cant seem to be sent to all clients unless its the owner.
In my game I need the server to receive the 1st person camera rotation from the client so that certain movements can be seen by other players that goes beyond just movement being replicated (where the eyes of the characters are looking and head rotation). Its very important since its a huge way to bring the player's character to life online. The rotation variable wont be recognized by the server; however, it just nulls to 0 on all fields (but the client works fine). I've tried to run a variable on the server that is based on the camera rotation, but it doesnt work either.
On the other end, I need clients on their HUD to know about global variables that the server is in charge of, such as player index numbers (whos player 0, 1, etc). If the server doesnt manage this, every player controller thinks it is player 0 because its not globally aware via the server that other players exist; but the server does. I need the HUD to be able to recognize who player 0 is and 1, etc so the right elements can display in the lobby menu and what not.
If this is me not understanding Game Modes and Game States and Player States, that would be understandable. If you got any sick or average ideas on how I could go about this, Id much appreciate it sirs
asked Mar 28 '15 at 01:52 AM in Blueprint Scripting
Okay, I am fairly new to Replication as well so bare with me. In short you don't need to replicate your camera to get rotations for movement. I have the Controller and the Pawn handle that, I actually "TearOff" my camera manager so that the client has full control of it and it's not constantly bugging the server to perform movements. Basically the camera follows the Controller's rotation, and the pawn also follows the controllers rotation. The Controller is constructed on the server, and replicated to it's owning client. If you have 5 players, the server has 5 pawns and 5 controllers. Each client has 5 pawns, 1 controller, and 4 player states. Each client is able to rotate and move their pawn on their clients, that is then sent to the server where the server updates it's own version of the controllers, and that gets replicated back down to each corresponding client. Replication is fun... and I'm not entirely sure all that is right lol but it DOES work on my game.
Now about the player index numbers. For every client, their own controller is the only one that exists locally, the others have a player state. That is also why on the clients their player index is 0. The server on the other hand has each player's player index starting with the controller that owns the game. As a side note the Game Mode only exists on the server as well, Each client recieves a Game State.
SO... if you want to have each client know what their player index is on the server store it in the Player State. However you probably shouldn't need to do this because most replication handles what controller did what automatically. However I don't know your reasons so that is about all I can say about it.
One of the most important things to remember is that "The Server is GOD". If the client wants to change something, they must tell the server they want to do it, then the server performs the operation and notifies the client the operation happened either by calling a client function, or replicating the changed properties down to the client (in which you can trigger other events on the client using a RepNotify function)
I have ready countless articles and wikkies and asked numerous questions on replication and I still feel I know next to nothing on this subject...
answered Apr 18 '15 at 06:36 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here