Download

E to interact replicated

Hi. I am still wrapping my head around replication. If I wanted to interact with a light switch would the server logic get called on player when e is pressed or on light switch when interact event is called on the switch itself?
Thanks

Hi, you would replicate it to the server directly when e is pressed, not in the light switch.

Generally speaking:

You can only call RunOnServer events on actors that you own. All actors can only have one owner. That means you never call RunOnServer events on an actor where you expect several clients to be able to do so (I assume you want all clients to be able to interact with the light switch and not just one specific client).

Also I wouldn’t do any game relevant logic (anything other clients need to know about) on a client, in such cases I would directly replicate it from the input event to the server and let the server handle everything else.

If you do things that are completely cosmetic (not game relevant all other clients never need to know about that), then you can do that completely on a client, but as soon as you want other clients to also know about that, better directly replicate it from the input event to the server and let the server handle everything. Then if you have things that the clients need to know about then you can replicate those from the server to the clients (e. g. in this case a bool repnotify variable stating whether the light is on or off and inside the repnotify function you turn the light on or off).