Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

newbie question - allocating viewId...

Discussion in 'Multiplayer' started by spookynote, Mar 16, 2009.

  1. spookynote

    spookynote

    Joined:
    Dec 16, 2008
    Posts:
    9
    Hi everyone,

    Just a quick question... in the example about allocating network view ID's:
    http://unity3d.com/support/documentation/ScriptReference/Network.AllocateViewID.html
    Code (csharp):
    1. function OnGUI ()
    2. {
    3.   if (GUILayout.Button("SpawnBox"))
    4.   {
    5.     var viewID = Network.AllocateViewID();
    6.     networkView.RPC("SpawnBox",
    7.     RPCMode.AllBuffered,
    8.     viewID,
    9.     transform.position);
    10.   }
    11. }
    12.  
    13. @RPC
    14. function SpawnBox (viewID : NetworkViewID, location : Vector3) {
    15.   // Instantate the prefab locally
    16.   var clone : Transform;
    17.   clone = Instantiate(cubePrefab, location, Quaternion.identity);
    18.   var nView : NetworkView;
    19.   nView = clone.GetComponent(NetworkView);
    20.   nView.viewID = viewID;
    21. }
    Why is the viewId generated first and passed through the RPC, as opposed to being generated in the SpawnBox function?

    I think this is a really fundamental concept about viewId's that I'm not quite getting, so a short answer would be really helpful for me.

    Cheers!
    spookynote
     
  2. spookynote

    spookynote

    Joined:
    Dec 16, 2008
    Posts:
    9
    Okay, after investigating further I think I understand now...

    It has to do with ownership. Whoever allocates the viewId has ownership over any network view that is assigned to that Id. Is that correct? And are there any other important distinctions I should know about?

    Thanks!