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.

RPC function: from who did it came?

Discussion in 'Multiplayer' started by dacloo, Nov 10, 2007.

  1. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Hi!

    I am fairly new to network coding in Unity, and one thing that confuses me a bit is how do determin a "player ID".

    What I am trying to accomplish is to assign a unique player ID to everyone in the game. Or does Unity do this already?

    When a RPC call is executed locally, how do I know from which player it came, and e.g Destroy that player?

    Thank you!
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
  3. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Aaah wonderful! Thanks.
    I was confused with some terminology.

    Magic stuff, this networking.
    I was surprised to see that Network.Instantiate does in fact does something similair to a "buffered NPC" call.
    I did instantiate some spheres when pressing the space bar, and another client who logged on later, was perfectly in sync with the level (which I did not expect).
     
  4. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Hmm but in your example, how do I construct the function?


    RPC FUNCTION CONSTRUCTION (?)
    Code (csharp):
    1. function chatMessage(info : NetworkMessageInfo, message : String)
    2.  
    RPC FUNCTION CALL (?)
    Code (csharp):
    1. networkView.RPC("chatMessage",RPCMode.AllBuffered, NetworkMessageInfo, stringToEdit);
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    info : NetworkMessageInfo must come last in the receiver. You don't need to put it into the networkView.RPC. It will just be used if it's in the function or ignored if it's not.
     
  6. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Wow. You're fast :)

    Thank you. I didn't know i wasn't supposed to treat it like a regular parameter. Something for in the docs?
     
  7. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    454
    My NetworkMessageInfo.m_Sender fields always have index 0, even though I have 2 clients and a server sending to each other. Create an RPC function with NetworkMessageInfo as the last parameter.
    Repro steps:
    1. compile and run a Unity app that uses Network via the C# scripting API, so that you have 1 server and 2 clients on the same machine
    2. connect the clients to the server
    3. send an RPC from NetworkPlayer 1 (RPCMode.Others). Notice that it is received with NetworkMessageInfo.m_Sender == 0
    4. send an RPC from NetworkPlayer 2 (RPCMode.Others). Notice that it is received with NetworkMessageInfo.m_Sender == 0