Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Unity Multiplayer Targetted ClientRPCs? All except one?

Discussion in 'Multiplayer' started by Shinyclef, Jun 16, 2015.

  1. Shinyclef


    Nov 20, 2013
    My situation is this:
    1. Client performs action.
    2. Client sends command to server.
    3. Server receives command and performs action.
    4. Server sends RPC to all clients.
    5. All clients perform action.
    In step 5, I believe the localPlayer (in the case of a host) is performing the action even though it was performed in step 3 (as the server). This can be avoided by returning if (isServer) in the RPC.

    However, is there a way to exclude the client who made the command from receiving the serialized RPC to save bandwidth? I'd prefer to only have to send the client a cancellation message if the server rejects the commands.
    I thought of returning on if (isLocalPlayer) in the RPC, but I think the network data would have already been sent at that point.

    My suspicion is there is no way to do this and I'll have to create my own messages for this, but I'd like to confirm before I commit to that path. If my assumption is correct, are there any plans for such a feature?

  2. seanr


    Unity Technologies

    Sep 22, 2014

    Code (CSharp):
    1. [ClientRpc]
    2. void RpcStuff()
    3. {
    4.   if (isLocalPlayer)
    5.       return;
    7.     // do stuff
    8. }
    The message is sent to that player, but they ignore it.

    It has come up to have a special type of ClientRpc that is not sent to a particular player, or even a special type of Command that is sent to the server AND then broadcast to all player objects on all clients (except the source)... But those features do not exist (yet).
    Lofar42 likes this.
  3. Shinyclef


    Nov 20, 2013
    Is it on the roadmap? This will influence my decision to go with your example code or to build the functionality via messages. Thanks for your reply.