Network.Instantiated objects appearing on server but not client

Hi All,

So to simplify the scenario let’s just say I have two scenes: the menu where connection happens and the level to walk around in. The server user (SU) will setup a game and load the Level scene, and once loading is done, call Network.Instantiate to make their avatar. Next the client (CU) comes along, connects to that game, and does the same thing.

At this point, the server has an object with the remote flag representing the connected client avatar(along with their own not remote avatar) but the client only sees himself. A few seconds later, the client gets this error (3 is the id for the SU avatar):

  • View ID AllocatedID: 3 not found
    during lookup. Strange behaviour may
    occur
  • Received state update for view id’
    AllocatedID: 3’ but the NetworkView
    doesn’t exist

Why isn’t the CU being told to load objects that were called via Network.Instantiate prior to him connecting? Did I miss a step somewhere?

UPDATE

Upon further testing I discovered that the object is being created on the client, but it’s being instantiated in the menu scene (on connection), not the Level scene (on proper scene load.) Furthermore, if after both parties are connected I instantiate an avatar in Level 2 (another scene) he appears for everyone else even if they’re on Level 1. This is not desired behavior.

How do I make it so an avatar only loads for every client when they’re in the same scene?

Refer to http://docs.unity3d.com/Documentation/Components/net-NetworkLevelLoad.html example, where RPC calls are deferred until the level has loaded.

Basically, Network.isMessageQueueRunning = false; is what you’re after to stop the instantiation from occurring before you’re ready to handle it. Where you use this will obviously be specific to your project. Also pay particular attention to Network.SetLevelPrefix(levelPrefix);, which will help prevent updates from ‘previous’ levels affecting the currently loaded level