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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

ClientRPC one Client?

Discussion in 'Multiplayer' started by LukasO, Nov 26, 2015.

  1. LukasO

    LukasO

    Joined:
    May 23, 2013
    Posts:
    115
    I can't see how to do this? Especially on reconnection in a game, I'd like to send a clientRPC to just one person. Is this possible?

    Thanks,
     
    Iron-Warrior likes this.
  2. mbouffard

    mbouffard

    Joined:
    Jun 28, 2013
    Posts:
    19
    Hello,

    I would call the Rpc call on the NetworkBehaviour instantiated for this person (which would exist on every client of the game), then check the property isLocalPlayer to execute the code only on that person.

    I don't know if this the optimal solution but I think this would work.
     
  3. LukasO

    LukasO

    Joined:
    May 23, 2013
    Posts:
    115
    But the problem I have is where there's a single instance of an object that's shared between the three of them. So for example a GameManager. I want to basically sync a client's version of the GameManager with the server's and the use of SyncLists/SyncVars isn't really enough or would be very difficult to work with. So what I'd like to send is an array of int[] in an rpc call where my clients then make a list of current players based on that array of player numbers. I don't need to send this to preexisitng clients as they've already set themselves up.
     
  4. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    836
    You can use NetworkServer.Send, which sends to a single, specific client.

    ClientRpc to single client would be great though :(
     
    CrandellWS likes this.
  5. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    I would also consider network bandwith consumption. I think an RPC is always being send to all clients. If only one client uses it's data, however, the data send to the other clients is not needed so a significant part of the consumed network traffic is just going to waste. This waste likely scales with the amount of players and the actual data you send. Anyway, a reconnection seems to be something that does not happen too frequently, so a little waste/redundancy might be acceptable in this case. In terms of raw efficiency, I guess sending messages would be a better solution though.
     
    Last edited: Nov 27, 2015
  6. LukasO

    LukasO

    Joined:
    May 23, 2013
    Posts:
    115
    Yeah I have seen NetworkServer.Send but as far as I'm aware you have to set up specific message types which feels rather overkill for a one shot message.
     
  7. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    836
    Agreed. I'm interested in any alternative solutions, since this seems like a problem lots of people have been running into (RPC to a specific client).
     
  8. shroeder

    shroeder

    Joined:
    Jul 20, 2018
    Posts:
    2
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'm going to venture a guess they weren't using TargetRpc because it was added in Unity 5.4, which was released in mid 2016, but this necro thread is from the prior year.
     
    CrandellWS likes this.