Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Inconsistent RPC behavior between player and IDE

Discussion in 'Multiplayer' started by AmazingRuss, Oct 19, 2008.

  1. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    933
    I am trying to have the server Network.instantiate a player vehicle when the player connects, and then use an RPC to tell the player which vehicle belongs to them:
    Code (csharp):
    1.  
    2.     //------------------------------------------------------------------------
    3.     void OnPlayerConnected(NetworkPlayer player)
    4.     {  
    5.         networkView.RPC("LoadLevel", player, Application.loadedLevel);
    6.  
    7.         GameObject ps =
    8.             Network.Instantiate( vehicle.Get(config.startingVehicle),
    9.                                              new Vector3(0,300,0), Quaternion.identity, 0)
    10.                                              as GameObject;
    11.  
    12.         Console.Set("id", ps.networkView.viewID);
    13.        
    14.         networkView.RPC("SetVehicle", player, ps.networkView.viewID);
    15.         qCamera.target = ps.transform;
    16.     }
    17.  
    18.     //------------------------------------------------------------------------
    19.     [RPC] void SetVehicle(NetworkViewID id)
    20.     {
    21.         try
    22.         {
    23.             Console.Set("id", id);
    24.             NetworkView nv = NetworkView.Find( id );
    25.             Console.Set("nv", nv);
    26.            
    27.             qCamera.target = nv.gameObject.transform;
    28.         }
    29.         catch(System.Exception e)
    30.         {
    31.             Console.Set(e.ToString());
    32.         }
    33.     }
    34.  
    This works fine if I am running the server in the player and the client in the IDE, however, if I run the client in the player, the RPC fails because the client cannot find the network view.

    I have tried looping on the NetworkView.Find() in case there is some delay in instantiation, but it never shows up.

    Can anyone suggest what I may be doing wrong?
     
  2. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    I am not sure if Network.Instantiate will set the networkView for 'GameObject ps' right away.

    Have you checked to see if
    Code (csharp):
    1. ps.networkView.viewID
    gives a valid and correct value?
     
  3. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    933
    Yes...it appears to be ok on both ends. The first time it's one, and increments every time I connect.
     
  4. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    933
    An update:

    It appears that the Network.instantiate is not creating the object on the client at all...which explains why the networkview cannot be found.

    This works fine when the client is run out of the IDE, but does not work when the client is built into a player.
     
  5. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Have the server write out to the debug window the client connect response and the calling objects rpc assignment. See what the client is asking of the server this way.
     
  6. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    933
    The client does not ask the server to do anything...the conversation goes like this:

    Client connects to server
    OnPlayerConnected fires on the server
    OnPlayerConnected calls an RPC to load the level on the client, Network.instantiates a vehicle (which does not show up on the client side when the client is built into a player), and calls an RPC on the client telling it the networkView id for the vehicle.

    The RPC then fires on the client, and attempts to find the networkview and attach the camera to the gameobject that contains that network view.

    As I understand network.instantiate, any objects that were network instantiated prior to a client connecting are buffered and instantiated on the client when it connects. This is how it works when the client is run in the IDE...everything works when the client is run in the IDE. It's just when the client is built that it stops working. It's soooooo frustrating!
     
  7. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    Is it possible that your vehicle prefab is not getting built into the standalone client?

    Network.Instantiate does not work with AssetBundles if you are using that.

    Are there any hints at what is going on in your output_log.txt?
     
  8. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    933
    AHA!

    Network.Instantiate on the receiving client failed because the asset couldn't be found in the project (Filename: NetworkManager.cpp Line: 2397)

    I had an array of prefabs references in my script, which I was using to make it possible to select the starting ship from a config file. I had populated it in the default references for the script, and in the server, but not the client.

    I didn't have an output_log.txt, but found the info in the OSX console viewer under unity/Player.log.

    I've tried removing/adding the script, as well as resetting it, but the default settings don't show up. Maybe I misunderstand what they are supposed to do.

    Anyway, the array reference was not enough to get the prefabs built into the project. I added another scene and instantiated the prefabs in it and everything worked.

    Thank you all for your help!