Search Unity

Unity wins the Award for "Stating the Obvious !"

Discussion in 'Multiplayer' started by will_w, Apr 28, 2009.

  1. will_w

    will_w

    Joined:
    Feb 20, 2008
    Posts:
    56
    I am slowly moving from total noob to semi-noob.

    I am working on instantiating, network ids, and RPCs right now. This is what the Script Reference has to say:
    That's it!? No further reading? No other examples? Not even a hint as to the gotchas.

    So now I head blindly in and will add multiple network views - as required by anything more than a damn cube.

    If anyone can either warn me or point me to appropriate reference on any gotchas or tips for this - please lemme know.

    Thanks in advance.
    Will
     
  2. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    When using network.instantiate this is all done automatically for you. If you instantiate it via "Instantiate" you'll need to manually assign all networkviewID's.

    For example;
    Have the server create two viewID's:
    Code (csharp):
    1.     var transformViewID : NetworkViewID = Network.AllocateViewID();
    2.     var animationViewID : NetworkViewID = Network.AllocateViewID();
    RPC them to the other clients.
    Have the clients instantiate the object, and simply assign the viewID's like this:

    Code (csharp):
    1. var instantiatedPlayer : Transform = Instantiate(playerPrefab, transform.position, transform.rotation);
    2.     var networkViews = instantiatedPlayer.GetComponents(NetworkView);
    3.    
    4.     // Assign view IDs to player object
    5.     if (networkViews.Length != 2) {
    6.         Debug.Log("Error while spawning player, prefab should have 2 network views, has "+networkViews.Length);
    7.         return;
    8.     } else {
    9.         networkViews[0].viewID = transformViewID;
    10.         networkViews[1].viewID = animationViewID;
    11.     }
    12.  
    Also see "AuthServerSpawnPlayer.js" in the networking examples for an example with Instantiate and two netview's.
     
  3. will_w

    will_w

    Joined:
    Feb 20, 2008
    Posts:
    56
    Awesome help!!

    Thanks much!

    -Will