This CouchKnights setup shouldn't work. But it does!

Hi All,

another example from the CouchKnights project that really confuses me.
This is how the movement is handled and the way I understand movement and variable replication this should never make the Remote player be able to mirror its movement to the Authority client.


Since there is no RPC involved here before the variable is picked up for the ‘Add Movement Input’ function, how the h**k does this work?
Because when playing this networked it of course does make Remotes’ player2 character move on both clients.

I thought that variables need to be replicated from the Authority? So why does this work?
(and of course when I try this setup in my project it doesn’t work)

Cheers

I’m not sure what you mean. The two little spheres on several of the nodes means that the action is replicated.

The spheres are on the variables and mean that they get replicated if set on the Authority instance of the character, ie the listen server in this case.
But here there’s nothing that makes them being set on the Authority. ‘Move Forward’ will be polled on Player2/Remote too.
So from what I can tell this shouldn’t work.

Why would a replicated set function be there in the first place unless it gives the function caller acess to the server set function?

That or add movement input contains built-in functionality that dispatches to authoritative version of the pawn and replicates down from there.

My money is on the first option though.

I call all that weird stuff “kicking contest with a horse”, unreal is full of it, but i do not blame epic, this is gigantic project and i do not think it is possible to even predict 10% of those weird interactions in code. All they can do is to sanitize as much as possible so we do not have crash every time we do something wrong. Rest is up to us.

More on topic, I do not create code (even if i seen it working in Epic example) unless i fully understand what is going on there. In case of this i would just go safe way do RPC to server then replicate it back to client.

Also there is no guarantee that whoever did this code knew better than us how it works. About year ago i had very hard time with redundant dependencies of functions in unreal (that stuff was fixed later), since then I always use most simple solutions i can find even if it makes more of that “boiler plate” code between.

I would imagine the “Add Movement Input” function has Authority/Remote validation baked into it. I haven’t looked at the cpp to confirm this but this is what I suspect.

Yeah there must be a built in Authority switch but that shouldn’t be enough, as far as I understand things, it would also need a built in RPC mechanism.
There were other things in CouchKnights that I also cannot explain so I think maybe I wont use it as a guide to set up my own networking/replication code.
Probably better to stick with documentation and tutes. Hopefully I can find another good networked example as it would have been nice to have a real world guide for how to do an actual game rather than just ‘clean concepts’ that the tutes provide.

I actually think the answer is the SET vector node. If you think about it, a “replicated” SET function makes 0 sense unless its a function that is “ROLE_AutonomousProxy”](A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums).