In my networked game, all players hold and swing a motion controller (like playstation move controller, a Vive handset, or a Leap Motion hand tracker). Specifically, each player in the game (who is a remote client) has (authoritative) control over the position and rotation of their right hand (just like the Oculus Toybox demo, for those that know it: [Toybox Demo for Oculus Touch - YouTube][1])
The issue is that players need to see the position of other player’s hands in realtime. This means that each client has to somehow authoritatively replicate their hand position from client to server, (breaks the Golden Rule in Unreal Networking, I know).
Right now, I’m doing this by having each client Pawn spam the server every Tick with a Reliable “Run on Server” function call (i.e. RPC) where the client basically says “my hand is at these coordinates now!”, and the server-side variable is set to RepNotify so all the other clients will eventually get it from the server.
Making a reliable call every Tick to the server seems to be creating a ton of network congestion and lag
While client hands are visible to all players now, they just teleport around and look super-choppy. Is there no automatic, built-in Unreal way to have clients smooth out things between replication events?
Any help would be very much appreciated. I have a feeling my current implementation would make every Unreal Dev cringe and say: “That’s definitely not the best way to do this!”
Not really a good solution, I just hacked in some partial solutions to alleviate the issues a bit:
To prevent the clients from spamming the server too much, I simply have the clients only make their reliable “Run On Server” call once every 20ms.
To prevent the hand movement being choppy, I looked up some of the “Client-side movement prediction” theory that you can find on a few sites talking about fast-paced multiplayer in video games. Basically, I just have the hands interpolate their position over time between updates from the server.
My original hope was that there was built-in functionality in Unreal 4 to do this, but it seems you have to hack-in the solutions yourself the best you can.
The one remaining issue I wish I could solve is that the server keeps telling the client pawn where it’s hands should be through replication. This is promptly ignored by the client because it already knows where it’s hands are (it’s actually reporting its hand positions to the server after all). Unfortunately, this is automatic due to variable replication, and there’s no way to tell the server to replicate to everyone EXCEPT the owning client.
To follow up on my last note (the last paragraph I wrote), it seems there is a solution now added in a recent Engine update:
For any property you don’t want replicated to the client who owns it (like a hand or cursor position), you can go to the variable in blueprints, and set its Replication Condition to “Skip Owner”.
Yeah, I basically used an implementation of “Snapshot Interpolation” that Gaffer describes wonderfully on his website here:
It works pretty well most of the time, but if you look at the last video at the bottom of the page, I definitely get those same movement oddities and artefacts during times of high/unstable lag.