SpawnObjects error, scene objects are not properly spawning on client

Hello,

I have some objects in my scene that are networked objects. As far as I can tell, the procedure for getting these to be activated on both the host and client goes as follows: register the prefabs on the client, then call NetworkServer.SpawnObjects() on the server. I’m going off this little article here for that, and I do it manually as I am not using the NetworkManager. I have done this, but I’m getting the following error:

Spawn scene object not found for 1
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

…where “1” is 1, 2, 3, 4 (for each of my four scene objects). Some things that I am certain of:

  • The objects are being registered, for sure, since I debug out all the registered prefabs after registering them just to be certain.
  • NetworkServer.SpawnObjects() is being called after the prefabs are registered on the client. To be sure of this, I spawn the objects after a brief intro menu at the start of each match which lasts 5 seconds, which the prefabs are registered immediately upon being loaded.
  • NetworkServer.SpawnObjects() does work on the host.

What I’ve tried:

  • Deleting my Library folder and rebuilding. Did not work.
  • Spawning different prefabs. I made a dummy object, registered it and placed it in the scene, but it also did not spawn (so it doesn’t seem to be object specific)

Totally lost here, not sure what else to try. Has anyone else run into this problem?

1 Like

Okay, so using the magic of ILSpy, the error message above gets called when ClientScene.spawnableObjects (a dictionary of all the networked objects in the scene) does not contain the key matching the scene id of the object you want to spawn. ClientScene collects these objects in the PrepareToSpawnSceneObjects() method. This, in turn, is called in the OnObjectSpawnFinished network callback that is registered as msgType 12, or SpawnFinished.

This message is then sent in the NetworkServer.SetClientReadyInternal…which is called by SetClientReady! So apparently, setting a client “ready” also preps whatever scene they’re in, and I was setting them ready in a custom lobby I had built (and clearly was not handling the scene transition between lobby->game correctly).

EDIT1: Apparently NetworkServer has an instance that doesn’t seem to survive scene change…despite the fact that the connections actually still work, which is pretty cool. Unfortunately, the object’s list of connections is not maintained, which means you cannot call SetClientReady :frowning:

EDIT2: Looks like EDIT1 isn’t true. Either way, setting all clients not ready before the scene loads and then resetting them ready seems to work. Whoof. That was some serious real life Indiana Jones work to dig through that.

2 Likes

:smile: Thank you very much! :smile: This is exactly what I didn’t understand!

You can also target specific connecting clients.

So, before loading a scene on a client you must set that client to not ready, then load the scene, then on some object within that scene set the client back to ready. The ready commands must be done on the server so you will need to either issue a command by a remote object or register some network message handlers.

void Blarg() {

//Tell server to set this player as not ready before loading a scene
NetworkMasterClient.player.CmdClientReadyToggle(NetworkMasterClient.ConnectionId(),false);

//now load the scene
UnityEngine.SceneManagement.SceneManager.LoadScene(msg.sceneToLoad);
}


[Command]
    public void CmdClientReadyToggle(int connectionID, bool setReady) {  

        //toggle ready state of a client
        if( setReady )
            NetworkServer.SetClientReady( NetworkServer.connections[connectionID] );
        else
            NetworkServer.SetClientNotReady( NetworkServer.connections[connectionID] );
    }

void Start() {

//tell server that this client should be ready now
        NetworkMasterClient.player.CmdClientReadyToggle(NetworkMasterClient.ConnectionId(),true);
}

Setting all clients not ready : How you do this? I didn’t find it yet. Please Provide ASAP

NetworkServer.SetAllClientsNotReady

Hi iron warrior, thanks for response i tried this code but actually my problem is persist. As i am loading an additive scene my network identity objects reamins disabled. I am loading scene something like this:

[ClientRpc]
    public void RpcLoadLevelAcrossNetwork() {
        NetworkServer.SetAllClientsNotReady();
        SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);

    }

I am using an rpc call so that everywhere new additive scene become loads. its loading the scene into client but with disable network identity objects. i have also ready the newtwork objects (as u suggested) in start even of my new loaded scene but this is also didn’t work.

void Start
{
     CmdActiveSpawnObject();

    }

    [Command]
    public void CmdActiveSpawnObject() {
    
        MyNetworkManagerWithVR obj = FindObjectOfType<MyNetworkManagerWithVR>();
     
        for (int i = 0; i < obj.networkConnectionList.Count; i++)
        {
            Debug.Log("connectionId : " + obj.networkConnectionList[i].connectionId);
            ClientScene.Ready(obj.networkConnectionList[i]);
        }
    }

I am hanged in this problem from last couple of days. Please can you help here? what i am doing wrong, why my additive scene’s network identity objects are false (although it is default behavior but why they are not enabling automatically as document suggested)

I’m stuck in a similar place. About half of the time my client loads the scene perfectly. However, half the time my client loads the scene and no player objects are loaded and the scene’s network identity object is inactive.

I’ve tried loading a new scene after the client connects, setting clients to not ready and then back to ready after loading that scene and making calls to NetworkServer.SpawnObjects() after the client connects. None of these seems to solve my issue.

Any help would be greatly appreciated, I’ve been stuck on this multiplayer issue for way too long.

The client always gets through “OnClientConnect” but when it fails "OnServerConnect’ never gets called after the client connection.