HasAuthority() vs Server RPC

Guys, whats the difference between this

and this

RepNotify only changes the widget text above player’s head to the random value

Switch has Authority is a Macro. It checks if the Actor executing the node has Network Authority.

Listen Server setup: Server/Host Player
Dedicated Server setup: Server

The following code would only work in a Listen Server setup. One in which the player (Host) inputs M.
On a dedicated server the Authority route would never be taken.

This is fine for a dedicated.


image

1 Like

I understand, but is there any difference between the codes of the last 2 prints you sent? The first using this switch and the second not using it. I mean in terms of behavior and/or performance. Is it correct to say that this switch is just a way to ensure that the code is executed on the correct side (server or client), and that I can achieve the same result using only RPC for example?

No real difference. The Authority node isn’t technically needed. Servers don’t press keys, so the logic only gets ran on clients.

I use them off inputs in prototypes to remind me that I need to split code (server-side modules) when I translate to C++.

If you have functions or events that both client and server execute it’s good to use them to control what server does vs client.

1 Like