I have a server and a client running the same code. I want X clients to be able to join a server. They all control a character (including the server) on a map. Pretty standard.
I can allow players to connect and disconnect, but if they try to reconnect, they get two errors and weird stuff start happening.
- View ID AllocatedID: 150 not found during lookup. Strange behaviour may occur
- Could’t invoke RPC function ‘FocusCameraOnObject’ because the networkView ‘AllocatedID: 150’ doesn’t exist
I’m also going to dump the javascript file in question in here, but it may not really be nesessary.
var playerModel : Transform;
var mapModel : Transform;
//add players and map
function OnPlayerConnected(player: NetworkPlayer)
{
networkView.RPC("startLoadingSelf", RPCMode.AllBuffered, player.ToString());
}
@RPC
function startLoadingSelf(player:String)
{
if(Network.player.ToString() == player)
{
addNewPlayer("player " + player);
}
}
function OnServerInitialized()
{
var newMapModel = Network.Instantiate(mapModel, transform.position, transform.rotation, 0);
newMapModel.networkView.RPC("renameObject", RPCMode.AllBuffered, "Map");
addNewPlayer("player " + Network.player.ToString());
}
function addNewPlayer(playerName:String)
{
var spawnPoint = GameObject.Find("Map/Spawn");
var newPlayerModel = Network.Instantiate(playerModel, spawnPoint.transform.position, spawnPoint.transform.rotation, 0);
newPlayerModel.networkView.RPC("renameObject", RPCMode.AllBuffered, playerName);
newPlayerModel.networkView.RPC("FocusCameraOnObject", RPCMode.AllBuffered, playerName, playerName + "/PlayerModel");
}
//remove players and map
function OnPlayerDisconnected (player : NetworkPlayer)
{
Network.RemoveRPCs(player);
removePlayer("player " + player.ToString(), "network");
}
function OnDisconnectedFromServer(mode : NetworkDisconnection)
{
Destroy(GameObject.Find("Map"));
var players = GameObject.FindGameObjectsWithTag("Player");
var i = 0;
for(var player in players)
{
removePlayer("player " + i, "local");
i++;
}
}
function removePlayer(playerName:String, netOrLoc:String)
{
if(netOrLoc == "network")
{
GameObject.Find(playerName).networkView.RPC("FocusCameraOnObject", RPCMode.AllBuffered, playerName, "World");
Network.Destroy(GameObject.Find(playerName));
}
else if(netOrLoc == "local")
{
GameObject.Find(playerName).GetComponent(GenericRPC).FocusCameraOnObject(playerName, "World");
Destroy(GameObject.Find(playerName));
}
var currentPlayer = GameObject.Find("World");
}