I’m working on a multiplayer game where I want to synchronize the usage of abilities (like player X used ability X). It’s peer to peer with Relay. If a client uses an ability, he could call a ServerRpc, which then informs all clients through a ClientRpc. But that’s very slow, and I thought it would be better if the client could inform all other clients directly. This way the information wouldn’t have to travel two ways (client → host, then host → all other clients), but only one direct way to all the clients.
That’s why I’m looking for a way to call a ClientRpc from a client.
But as far as I know, that’s not possible. (or is it?)
Is there a better way to do it?
Network variables don’t seem right to me for that problem, since it’s just a one time event (activate ability X for player X), and not a persistent state.
As far as I know, [quote]
A ClientRpc can be invoked by the server to be executed on a client.
[/quote]
Which makes sense since Netcode has a Server authority design.
On the other hand, do you really want to give the Client the ability to control the game flow? Remember, never trust the Client.
As far as I understand, you recommend me to make a ServerRpc which then calls a ClientRpc to inform all other clients. I was hoping that there would be a “faster” or more direct way of telling the other clients about the event, because latency is a key factor in my game. On the other hand, you are also right about not trusting the clients…
I want to call the ClientRpc to execute locally beforing sending a ServerRpc to call the clientRpc on all clients instances, excluding the one that just called it and sent the ServerRpc.
One workaround is to create a local method that will be encapsulated in the ClientRpc. But instead of calling the ClietRpc, just call this method, then send the ServerRpc.
I am not willing to write up my script to test wheter this is possible, because it will take me a while to self test this, but I will come back with an answer soon. Althought from the sources I have read, there is not any info provided about calling ClientRpc on the client to execute on the local instance.