Search Unity

Network Instantiate not working as described?

Discussion in 'Editor & General Support' started by jason, Oct 15, 2007.

  1. jason

    jason

    Joined:
    Oct 12, 2007
    Posts:
    19
    I'm attempting to instantiate the fps prefab, however it is not working like the documentation suggests.

    Upon connecting, I have each client call Instantiate() on the fps prefab. According to the docs:
    That doesn't happen. One client ends up controlling all of the instances.


    That doesn't happen either. After the second client connects, the first client receives the Instantiate automatically, but the second client does not recieve the "buffered" Instantiate. The result: the second client can not see the first.


    Maybe I misunderstood something?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Control in this context means that one machine sends data, where as other machines only receive the data.


    Network.Instantiate buffering works fine in all our tests, maybe you are removing the instantiate fromt the rpc buffer via Network.RemoveRPCs

    Or possibly you are calling Network.Instantiate prior to having connected. That is you received the OnConnectedToServer call.

    We will upload a networking sample project that shows different networking approaches during this week.
     
  3. jason

    jason

    Joined:
    Oct 12, 2007
    Posts:
    19
    I am using RemoveRPCs when the player is disconnected, is this incorrect? However, the error occurs before any players are disconnected.

    The Network.Instantiate is also inside the OnConnectedToServer.

    I'm a little confused. Should both the player and the other players it can see, both reference the same prefab? Or should the other players that you don't have control over be a separate prefab without a camera/inputs?

    Here is the server code:

    Code (csharp):
    1.  
    2. function Start() {
    3.     Network.InitializeServer(32, 25000);
    4. }
    5.  
    6. function OnPlayerDisconnected(player: NetworkPlayer) {
    7.     Debug.Log("Clean up after player " +  player);
    8.     Network.RemoveRPCs(player);
    9.     Network.DestroyPlayerObjects(player);
    10. }
    11.  
    Here is the client code:
    Code (csharp):
    1.  
    2. var playerPrefab : Transform;
    3.  
    4. function Start () {
    5.     ConnectToServer();
    6. }
    7.  
    8. function ConnectToServer () {
    9.     Network.Connect("196.72.149.24", 25000);
    10. }
    11.  
    12. function OnConnectedToServer() {
    13.     Debug.Log("Connected to server");
    14.     Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
    15. }
    16.  
    17. function OnFailedToConnect(error: NetworkConnectionError)
    18. {
    19.     Debug.Log("Failed to connect to server");
    20. }
    21.  

    I look forward to seeing the new examples.

    Thanks
    -Jason
     
  4. Murphy

    Murphy

    Joined:
    Oct 28, 2007
    Posts:
    1
    "Network.Instantiate on the receiving client failed because the asset couldn't be found in the project"

    This error is in the console when I try to instantiate a mesh on the server when a client connects. They are using the same prefab so I don't understand how assets can be missing. Any idea what this could mean?
     
  5. marshmonkey

    marshmonkey

    Joined:
    Oct 17, 2007
    Posts:
    10
    any news on the networking sample project?
     
  6. Mr. Animator

    Mr. Animator

    Joined:
    Oct 2, 2005
    Posts:
    193
    I've been able to Network.Instantiate prefabs successfully without a hitch, the only difference being that I haven't tried instantiating as a result of someone connecting. I can't imagine why, but maybe its having trouble because you're instantiating across the network while simultaneously connecting and there's some latency related confusion. Do you still have problems if you try to instantiate well after the connection has already been made?