Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NetworkPlayer parameter support in RPCs

Discussion in 'Multiplayer' started by JohnGalt, Feb 11, 2008.

  1. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    Is it possible that when calling:

    RPC(string, NetworkPlayer, ...)

    it doesn't support NetworkPlayer as parameter??

    Maybe is just the version with RPCMode the one which supports it?
     
  2. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    AFAIK, it only works on the server. You cannot directly send RPCs from players to other players. I might be wrong, though...

    Jashan
     
  3. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    No, sorry, I explained myself badly. I meant as a parameter, like in:

    RPC("RPCFunctionName", targetPlayer, parameterPlayer)
     
  4. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    You are correct Sir!

    Yes, only the server has the correct NetworkPlayers' infos. What I did was to have the server send a message to everyone with the NetworkPlayer of their opponents.

    EDIT
    Oh, and sorry, just saw that you were talking as a parameter, but it works, for example in my code I have (only in the server!):

    Code (csharp):
    1. networkView.RPC("sendPlayerNetworkInfo", RPCMode.Others, m_player.getUsername(), m_player.networkView.owner);
     
  5. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    But you are using the RPCMode version! ;))

    I was talking about the combination of sending to a NetworkPlayer using a NetworkPlayer as parameter:

    networkView.RPC("SendIt", targetPlayer, parameterPlayer);
     
  6. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    Oh, sorry, haven't used that way.
     
  7. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    well NetworkPlayer is a supported parameter type of RPC, and I don't see why it should be dependent on which RPCMode you are using, as long as you have the right NetworkPlayer, which only the Server knows, as nafonso mentioned. Have you tested it? And it doesn't work? Maybe Larus needs to drop by and confirm....

    http://unity3d.com/support/documentation/Components/net-RPCDetails.html

    Cheers.
     
  8. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    277
    It's possible to use NetworkPlayer as a parameter in RPCs, also when using specific target players (not RPCMode).

    This should work. I just tested something virtually identical to that. So, maybe its something else? What error are you getting?
     
  9. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    I'm having troubles using RPCs to a NetworkPlayer.

    It works if the sender OR receiver is the Server, but if I try to send from one Client to another, I get the following messages in the receiver's Debug Log:
    I got around it by sending everything through the server, and then the server sends to the specific NetworkPlayer.

    As anyone experienced the same problem?

    Regards,
    Afonso
     
  10. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Hi Afonso,

    AFAIK, you can only send RPCs directly to NetworkPlayers from the server. And it seems you can also send directly to the server using the "server NetworkPlayer"... Since all messages go through the server anyways, it's probably no problem to send to the server and distribute from there (aside from being a bit more code ;-) ).

    Sunny regards,
    Jashan
     
  11. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    AAAAH thanks! Yes, I noticed that they went through the server, because only when the server browser window was active, the RPC would try to be called :p

    This should be mentioned in the docs. Since it wasn't, my server sent all the NeworkPlayers to everyone so they could interact directly. And when trying with only one client, everything worked, so with more clients I was getting very confused!

    Now I'll start winning more easily! I was the only one getting the lines of every player! hehe

    Regards,
    Afonso