Search Unity

first rpc from OnPlayerConnected

Discussion in 'Multiplayer' started by Ghidera, Apr 20, 2014.

  1. Ghidera

    Ghidera

    Joined:
    Mar 6, 2013
    Posts:
    53
    I'm playing with a dedicated server setup and I've just gotten to the point where the server and client connect ok. On the client I've already gone through creating a list of servers, saving away the information, then having the user click connect.

    The client connects to the server fine and now I want to tell the client to authenticate (acct and password). From the server I'm trying to use an RPC like this:

    Code (csharp):
    1.  
    2.     void OnPlayerConnected(NetworkPlayer player) {
    3.         Debug.Log("Player connected");
    4.         networkView.RPC("StartLogin",player);
    5.     }
    6.     [RPC]
    7.     void StartLogin() {
    8.     }
    9.  
    On the client I have this

    Code (csharp):
    1.  
    2.     [RPC]
    3.     void StartLogin(NetworkMessageInfo mInfo) {
    4.         selectionStage = selectionStages.LOGIN;
    5.         chat.MessageFromThisClient(chatMsgType.SUCCESS,"Server requests Login");
    6.  
    7.     }
    8.  
    When the client connects it gets the error

    Could't invoke RPC function 'StartLogin' because the networkView 'SceneID: 1 Level Prefix: 0' doesn't exist

    After much fumbling around I think it's because the networkview ids are different on the server and client. Looking at the inspector the networkview says its ID is 1 and on the client it is 2.

    How can I send an RPC to the specific client or client to the server when the IDs aren't the same and at this point I see now way of telling each other what the IDs are?

    Thanks!
     
    Last edited: Apr 20, 2014
  2. Ghidera

    Ghidera

    Joined:
    Mar 6, 2013
    Posts:
    53
    i messed with this a bit then created a small project with just a couple GOs with a networkview each and two scripts for server and client. Right off the bat my RPCs worked fine.

    I went back to the original project, deleted the networkviews and every bit of code having to do with views (left the RPCs). added new views, turned off compression and observed nothing on both and voila, the RPCs worked perfectly. I have no idea why it was giving me problems originally as I started out with just views set this way...Oh well.
     
  3. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
  4. Beau Lee

    Beau Lee

    Joined:
    Dec 7, 2014
    Posts:
    1
    This isn't the answer, or you may not be understanding the phenomena Ghidera is describing. Calling AllocateViewId() is for when you can already communicate via RPCs and you want to send a specific ViewID to all clients.

    The problem we've experienced is when the client and server have connected, but not been successfully able to send an RPC. Client and Server are in separate Projects, like a dedicated server and client. Since we can't hard-code the ViewID we get errors.

    Like OP, I have the RPCs on both client and server. I have a simple blank _Communicator object with a NetworkView and script. Everything has the same name on both client and server. Following all the Unity documentation, and it still doesn't work.