Scene Object Not Spawning on Scene Load

I am referencing this page of the docs.

Then, when the scene is fully loaded, NetworkServer.SpawnObjects() is called to activate these networked scene objects. This will be done automatically by the NetworkManager when the server scene finishes loading…

I am not seeing this behavior in 5.2.1f1.

I load a scene (on the host) that has an object with a network identity attached. That object is disabled when the scene finishes loading. It is not being activated, as I believe it should, based on the documentation. In the prior scene I have a Network Manager that is not unloaded with the scene (so it is still active on scene load).

Can anybody shed some light on my issue?

1 Like

Bump. I’m stumped.

Here is a very very simple example. Start the host, then click the button to load the next level.

Per the documentation, when the scene is finished loading, the host should activate the cube (which has a Network Identity).

https://dl.dropboxusercontent.com/u/4231220/DemonstrateNotActivating.unitypackage

Same behavior in 5.2.2f1.

Can anybody besides me reproduce this? Is it a bug or is my project not doing things the way it should?

the networkidentity must be on a root object in the scene, not a child object.

@seanr
Thanks for the reply. I tried moving the object to be a root object, and the issue remains. Modified demo project at…

https://dl.dropboxusercontent.com/u/4231220/IssueWithNetworkObject.unitypackage

I have the same issue. My scene objects do not automatically load either (On the LocalHost they are enabled, but on LocalClient they are disabled and never “spawned”). They have NetworkIdentity on the root of the object and the documentation says sceneObject spawning should be automatic… so I’m not exactly sure what is going wrong.

As a solution I have a persistent singleton object with this code that seems to fix it. Unsure why this bandaid is needed though, I feel like I’m not doing something right or there is some bug preventing things from spawning (I’ve had issues with NetworkTransform and SyncList’s preventing scene objects from spawning. Bug: SyncListFloat Crashes NetworkAnimator - Unity Engine - Unity Discussions).

In any case create a persistent object and slap this code on it and see if this fixes your issue.

private void Awake()
{
   DontDestroyOnLoad(this);
}

private void OnLevelWasLoaded(int level)
{
   if(isServer)
   {
      NetworkServer.SpawnObjects();
   }
}
2 Likes

@Zullar Thank you very much for your workaround. I’ll wait for @seanr to reply, but then I think I will report this as a bug.

@Zullar

I tried your workaround and I only have partial success. The object is activated on the LOCAL client. However, on remote clients it is still disabled and I get an error:

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

OK. Few more questions.
-Are you using a custom NetworkManager?
-Are you using NetworkTransform?
-Are you using SyncLists?

Somehow for me it seemed these things affected the spawn messages that are sent (not 100% sure). I saw really strange things. Doing things like deleting my SyncList would cause sceneObjects to spawn properly, or re-arranging components in the object heirarchy could also turn the scene object spawning problem on/off. If we can pinpoint the exact scenario that is causing our sceneObjects to fail to spawn then hopefully SeanR can help fix the bug.

In my actual project I am. But in my example scene (linked to above) I am not.

No, I am not.

In my actual project I am. But in my example scene, I am not.

I cannot repro this is 5.2.2p1

I’ll grab the patch and try with my project linked above.

@seanr BTW, did you test w/ my project?

Thanks

yes

First off, thank you @seanr for looking into this matter. I appreciate the support.

I have downloaded 5.2.2p1 and it is an improvement. Now, the object is enabled on the local client. However, it is still deactivated on any remote client.

You can see this in my example project by building and running as host, then pressing the button to load scene two. Then, in the IDE, run and choose to be a client. Then click the button on the client to load the same scene. You will see the cube is created, but it is disabled.

If I remember correctly, it wasn’t even being enabled on the local client, so this is an improvement. I guess I should check the bug list and see what was included in p1. Maybe I can find the existing bug and add this info.

1 Like

The only fix in the patch that may be related, that I can see is this one. Otherwise I don’t know what changed the behavior with the local client.

Are you saying this happens when you run “Application.LoadLevel(1);” on the client?

That will not trigger networked objects in the scene to be enabled. This page should probably mention that…

http://docs.unity3d.com/Manual/UNetSceneObjects.html

NetworkManager.ServerChangeScene() is used to do this.

@seanr If you make one change to LoadIt.cs…

    public void OnClick()
    {
        //Application.LoadLevel(1);
        NetworkManager.singleton.ServerChangeScene("Scene Two");
    }

Then build and run as host. Scene Two is loaded and cube is active on local client. Then run in the IDE and choose client. Upon being connected this remote client automatically loads Scene Two, the cube is present but still disabled.

@seanr
Do you have a working example I can import? As of now, I haven’t see it work properly and plan to file it as a bug.

Thanks

I cannot reproduce this problem. Feel free to make a bug submission, then QA will look at it.