Replicated variable modified by a client

Hi,

I have a question about replicated variable, the video tutorial only talk about server side modified variable, and even said that we shouldn’t try to modify them on the client, but I’m stuborn and that’s exactly what I would like to do :), let me explain:
I didn’t think about multiplayer until now, as it is now, my controller class handle the input events and setup differents variable (MovementVector, iShooting, etc). Then in the event tick I call some functions to use these variable.
So I’m wondering if it could work (and if it’s correct design), to put these “input variable” as replicated, so the client would update them to the server, and then just run the function applying the result server side.

In other games engine I used, when setting up replicated variables, I used to select between “server to clients” or “owner to server” mode.

edit:
So I tested, and it seem that variable changed on the client are not replicated to the server by default.
Is there a way to change that behaviour ?
Is sending an RPC every frame with the updated value of these variable like in this thread(pinguin’s huge post) is really the way to go ?
It sound to be and huge, useless, overload to me… (and futhermore he use reliable RPC, so that sugest me that he really don’t know what he is doing either…)

Hey, Penguin here. :slight_smile:
That was like my first few post while start learning UE4 and have no previous UDK experience, so you are **** right I am just showing what I found working.
(without knowing if that’s the proper way to do things.)

We can break it down to 2 things.

  1. Movement Component, the one properly setup is CharacterMovement. I don’t think there is one generic movement that are ready for use for static mesh based.
    So from experience, you can assume that setup the entire thing to be efficient with just blueprint is a bit difficult as you have to also try to do some optimization to reduce updates.
    (ie. only update if the input axis value changes, use previous value if server didn’t update variables on client side, etc.)

  2. update to server or notify server and then fetch updated value are approaches. In games that allows super speed, crazy jump, infinite sprint, etc, you can bet they don’t do those on server side, or some checks are done on client that gets exploited.
    It’s pretty much a playability over high latency and secure update to prevent cheat trade off. This was discussed on some previous thread so I won’t cover them again.

Now, to your question. To use tick to try update server is much more inefficient, as network tick and event tick are run at different speed, you would be trying to force update but they are just in the queue, maybe even repeated.
The best compromise I think that’s necessary is to design your mechanism accordingly, if one value does not hurt the game even if it’s being hacked, then you can just try update the final result(ie don’t update the boost gauge and direction, just update the final speed and if it’s the same from previous frame, don’t update at all. bad example, but some game if you boost you lost ability to say shoot, so mechanism is first priority.)

Now to the replicated variable, yes, it is possible to just let server or client set it and then let replication do it’s job.(at least that’s what I think in the beginning.)
Even if you don’t send a RPC, you still have to update something, then it all comes down to what are updated, and how frequent.
In my example I only have to update 2 vectors for any update, client do the calculation and server apply it like you wanted, so even if in this case people can hack the input axis value to increase maximum force sent over to server, I can always clamp it and then apply default multiplier. If the movement rules grows, we can still refer to how character movement is setup and either do it in C++ or do some components to offer same functionality in blueprint.

Anyway, the input control update part is interesting, for blueprint I know some input like mouse location are pretty much per tick update, I don’t know about joystick axis.
So if you have more efficient update method, feel free to share it. :slight_smile:

And, it’s much later I read about this article for UE3, I did the reliable RPC mistake before realize how stuff really works. Haha.
http://wiki.beyondunreal.com/Everything_you_ever_wanted_to_know_about_replication_(but_were_afraid_to_ask)#Reliability

Hi, thanks for your answer. First don’t take me wrong I’m glad you posted that other post. And thanks for sharing that link that I missed.

About the variable replication, as I said it seemed that it’s the server that as authority over the variable and that they are not uploaded if modified client side, and I didn’t find a way to configure that behavior. I you say that you managed to make that work then I’ll run some more test, maybe I made it wrong.
From my previous experiences and networking school classes, sending multiple RPC every frame is just like trying to DDOS your own server, RPC’s should be kept from very specifics event: grabbing a weapon, pushing a button, etc.
The update function can run an hundred times by seconds or even more, while replicated variable are usually synchronized around fifteen time by seconds (if constantly changing), by the way that’s why clients implement interpolation.

Now, are you saying that Character’s should be synchronized out of the box ? It would match what I have seen in the networking video’s, I indeed inherit from the character class but that’s not the behavior I’m experiencing, i’ll look into it.

edit another related topic that I would like to keep track here: https://answers.unrealengine.com/questions/26116/able-to-replicate-movement-when-using-addmovement.html
Finally that’s my code to upload my variable, sadly it seems it’s the proper way to do it (I know it’s small, but it’s just “if remote client then upload all the var to the server with an RPC” (used on the control class, so it can only be the owner)), it’s coming from the Tick event:

Yeah, if you set replication, unless you have authority check and let the server side set the variable, it didn’t propagate the other way.(Like Tom’s example)
(Epic could change this behavior at anytime, so like you said, do tests would get rid of doubts.)

Also, from the link I shared, if you see the fine text, you will see description that they get rid of all the repetitive packets on receiving end, I would assume that Epic did similar for the out going queue as well.
Since network tick is not on the same rate as Event tick, I think all the update you call that RPC eventually only sends the last update when network tick happens.
And then server will update your character or pawn movement component to make them in sync.
Epic also have a recent video series talking about optimization, it’s a really long video about how you can optimized different aspect of things, I don’t know if it covers networking part as I dropped midway through.
I’ll check it again. But they have internal statistics that you can show network usage, like the amount of updates and such. here is the link:UE4 Rivalry Demo: How to Scale Down & Not Get Caught | Live Training | Unreal Engine - YouTube
Here is the recent blog post about simulate lag:
Finding Network-based Exploits - Unreal Engine

and here is my original answerHub question asking to show network statistics: