Hi all,
I’m trying to have multiple networked players running around and all able to see each other and the player’s respective minimap icons. The players show up fine, but any existing players’ minimap icons don’t show up when a new client joins. I’m not sure why, since the call to instantiate the icon is nearly identical to the one used to instantiate the player (see code below). The docs for Network.Instantiate() don’t say so explicitly, but I read in the forums that it gets translated to a buffered RPC. When I run a client in the Game view, I get the following console error mesage:View ID AllocatedID: 2 not found during lookup. Strange behaviour may occur
I read elsewhere on the forums that it shouldn’t happen using Network.Instantiate(). Can someone guide me in the right direction or explain what I’m doing that’s causing the instantiation to not be buffered? Thanks.
function CreatePlayer () {
var myPlayer : Object = InitializePlayer();
InitializePlayerCamera(myPlayer);
var myIcon : Object = InitializeMinimapIcon(myPlayer);
InitializeToolbar(myPlayer);
InitializeMinimapCamera(myPlayer, myIcon);
}
function InitializePlayer () : Object {
//The player is instantiated on the network.
return Network.Instantiate(playerPrefab, playerPrefab.transform.position, playerPrefab.transform.rotation, myGroup);
}
function InitializePlayerCamera ( myPlayer : Object ) : Object {
//The player camera is instantiated locally, so use GameObject.Instantiate().
var myCamera : Object = GameObject.Instantiate(cameraPrefab, cameraPrefab.transform.position, cameraPrefab.transform.rotation);
myCamera.transform.parent = myPlayer.transform;
var playerClickSelection : PointAndClickSelection = myPlayer.GetComponent(PointAndClickSelection);
if (playerClickSelection myCamera.camera) {
playerClickSelection.SetCamera(myCamera.camera);
}
return myCamera;
}
function InitializeMinimapIcon ( myPlayer : Object ) : Object {
//The minimap icon is instantiated on the network.
var myIcon = Network.Instantiate(minimapIconPrefab, minimapIconPrefab.transform.position, minimapIconPrefab.transform.rotation, myGroup);
var iconScript : NetworkMinimapIcon = myIcon.GetComponent(NetworkMinimapIcon);
if (iconScript) {
Debug.Log("Icon script found for player " + networkView.viewID.owner.ToString());
iconScript.SetMinimapIconTarget(myPlayer.transform);
}
else {
Debug.LogError("Minimap icon not properly initialized for player " + networkView.viewID.owner.ToString());
}
return myIcon;
}
function InitializeToolbar ( myPlayer : Object ) : Object {
//The toolbar is intantiated locally.
var myToolbar : Object = GameObject.Instantiate(toolbarPrefab, toolbarPrefab.transform.position, toolbarPrefab.transform.rotation);
myToolbar.transform.parent = myPlayer.transform;
myToolbar.name = "Toolbar";
myToolbar.BroadcastMessage("SetPlayer", myPlayer, SendMessageOptions.DontRequireReceiver);
return myToolbar;
}
function InitializeMinimapCamera ( myPlayer : Object, myIcon : Object ) : Object {
var minimapCamera : Object = GameObject.Instantiate(minimapCameraPrefab);
var minimapCameraScript : MinimapCamera = minimapCamera.GetComponent(MinimapCamera);
minimapCameraScript.SetTarget(myIcon.transform);
if (minimapCamera.camera) {
var playerToolbar : PlayerToolbarScript = myPlayer.GetComponentInChildren(PlayerToolbarScript);
playerToolbar.minimapCamera = minimapCamera.camera;
}
return minimapCamera;
}