Search Unity

Targetted ClientRPCs? All except one?

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

  1. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    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?

    Thanks.
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    So:

    Code (CSharp):
    1. [ClientRpc]
    2. void RpcStuff()
    3. {
    4.   if (isLocalPlayer)
    5.       return;
    6.  
    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

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    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.