Unity: Networking errors when changing scenes.

I had a really simple project set up that had two scenes, “Init” which I use to connect to server, and “Main”, where all my synced objects using networkViews are.
When the player had connected to the server I’d change to “Main” where I wanted all the objects already on the server to automatically show up.
However every time I ran the project I got these three errors:

ms_IDToPointer->find (obj->GetInstanceID ()) == ms_IDToPointer->end ()
View ID AllocatedID: 1 not found during lookup. Strange behaviour may occur
Received state update for view id' AllocatedID: 1' but the NetworkView doesn't exist

What was happening was that the server was sending us the objects before we had a chance to load “Main”, which was weird because I was using “Network.isMessageQueueRunning = false;” before connecting to the server and turning it back on when “Main” was loaded.

Fortunately this has a simple fix, apparently you have to set isMessageQueueRunning AFTER calling Network.Connect(..). I moved it to “void OnConnectedToServer()” and everything worked fine.

Init.unity

void Start()
{
	// Don't set isMessageQueueRunning here
	Network.Connect(hostData);
}

void OnConnectedToServer()
{
	Network.isMessageQueueRunning = false;
	Application.LoadLevel("Main");
}

Main.unity

void Start()
{
	Network.isMessageQueueRunning = true;
}

Tags: , , , , ,

Leave a Reply