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. Dismiss Notice

RPC called when Run from Unity but not in .exe

Discussion in 'Multiplayer' started by bartje86tralala, Aug 1, 2012.

  1. bartje86tralala

    bartje86tralala

    Joined:
    Aug 1, 2012
    Posts:
    7
    When I host my server from unity (through play button) the RPC's called from the clients are correctly synced across all clients. Howerver, when I make a build from the server and start the exe it doesnt pass along the rpc calls from the clients?

    So when run from within unity, everything fine, as soon as I make a built the rpc's are not called anymore...

    I tried building for Win32 and 64 bit stand alone.

    here is an example from how i initiate an RPC, they are called from the client's.

    PS. i tried RPCMode.Others, but then it fails always.. What i actually want is to send it to the server and have the server
    send it to all but the recipient.

    PS2. Network views are attached to the objects, the scipts are attached, no data is observed in the network view and the sync mode is set to off. Further more, no errors or warnings are given on either the client or server and network dubugging information has been set to full. Both client and server have the Application.RunInBackGround set to true.

    Code (csharp):
    1.  
    2.  
    3. function UpdateOurself()
    4. {
    5.         networkView.RPC("ObjectSync", RPCMode.All,
    6.                         transform.position,
    7.                         transform.rotation);
    8. }
    9.  
    10. @RPC
    11. function ObjectSync(position : Vector3, rotation : Quaternion, info : NetworkMessageInfo)
    12. {
    13.     if (networkView.isMine)
    14.     {
    15.         return;
    16.     }
    17.    
    18.     if (!Network.isServer  mSmooth)
    19.     {
    20.         mObjectPositionBuffer[mObjectPositionBufferIdx] = position;
    21.         mObjectRotationBuffer[mObjectPositionBufferIdx] = rotation;
    22.         mObjectTimeBuffer[mObjectPositionBufferIdx] = info.timestamp;
    23.         mObjectPositionBufferIdx = (mObjectPositionBufferIdx + 1) % mMaxBufferSize;
    24.         return;
    25.     }
    26.    
    27.     transform.position = position;
    28.     transform.rotation = rotation;
    29. }
    30.  
     
  2. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    Did the clients connect to the server successfully? I'd suspect firewall problems if not.
     
  3. bartje86tralala

    bartje86tralala

    Joined:
    Aug 1, 2012
    Posts:
    7
    Yes clients connect correctly. I have now investigated the problem a little more and it appears that objects created fron an OnGUI action with Network.Instantiate are not created on the server and therefore not synced but are however, created on other clients. Extreamly weird, especially as it work does when the server is run in unity only.
     
  4. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Not wierd at all, if you instantiate in the OnGUI, then the instance that pushed on the gui button owns the object.
    If you want the server to be the owner ( auth ) then you need to send an RPC to the server and request to instantiate.
     
  5. bartje86tralala

    bartje86tralala

    Joined:
    Aug 1, 2012
    Posts:
    7
    Thats what I do. When in OnGUI, a GUILayoutl.Button() is true, i call network.instantiate from the client side.
    Anyways i solved the problem. I created 2 scenes, one for client one for server, the server however had no link to the prefab in any of its scripts so unity decided to not include the asset in the build version whereas it does for the client. No warnings whatsoever are given when a new object is instantiated though from the client (yet the server didnt create it). I now include both the client and the server scene in the build so that all required assets (even though the server may not need them all) are included.