13

Short Description: I am loading an Additive Scene in my Main scene, its loading fine but Additive scene's GameObject (that contain Network Identity Component) are becoming disable.

Details: I am loading an additive scene through this code so that an additive scene become load into my server and all clients which working fine:

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

Although it has loaded my scene into clients/server but the object that are with network identity are disable (It is default behavior as I checked Unity UNetSceneObjects which states that:

All objects in the scene with a NetworkIdentity component will be disabled when the scene is loaded; on both the client and the server. 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 - or can be called directly by user code.

As documentation state that it will automatically activate the Network Identity objects but it did not happen in my context. My scene loading is fine but its network identity objects are not active.

What I am doing wrong?

I also tried to activate the object my self through calling NetworkServer.SpawnObjects() in my new loaded scene but it only spawning the object on server side while showing the error at client

Spawn scene object not found for 1 Spawn scene object not found for 2 Spawn scene object not found for 3..... . . .

Can any Unet Champion help me?

EDIT/UPDATED Approach:

I have changed my code according to the unity forum discussion for additive scene loading, its loading my additive scene on server with error (given below) and still my client side's scene network identity objects are disabled:

Error:

Ready() called with invalid connection object: conn=null

Another Code Try:

 #region AdditiveSceneLoadingSetup

    [Command]//calling this for additive scene load- its start
    public void CmdLoadAdditiveSceneMainCall() {

        RpcLoadAdditiveScene();
        StartCoroutine(LoadAdditiveSceneAtServer());

    }

    [ClientRpc]
    public void RpcLoadAdditiveScene() {
        Debug.Log("RpcLoadAdditiveScene");
        StartCoroutine(LoadAdditiveSceneAtClient());
    }

    public IEnumerator LoadAdditiveSceneAtClient() {
        Debug.Log("LoadAdditiveSceneAtClient");
        yield return SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
        List<NetworkConnection> networkConnectionList = FindObjectOfType<MyNetworkManagerWithVR>().networkConnectionList;
        for (int i = 0; i < networkConnectionList.Count; i++)
        {
            ClientScene.Ready(networkConnectionList[i]);
        }
        //ClientScene.Ready(this.connectionToServer);//connectionToServer
    }

    public IEnumerator LoadAdditiveSceneAtServer() {
        Debug.Log("LoadAdditiveSceneAtServer");
        NetworkServer.SetAllClientsNotReady();
        yield return SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
        NetworkServer.SpawnObjects();
    }


    #endregion AdditiveSceneLoadingSetup
Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186
  • I don't know anything about unity3d or the other stuff you are working with, but `SceneManager.LoadSceneAsync` looks suspicious to me. Shouldn't you work with the returned `AsyncOperation` somehow in order to determine the loading result? – grek40 Jan 30 '17 at 11:50
  • @grek40 I guess there is not problem regarding this line, its loading the scene perfectly. – Muhammad Faizan Khan Jan 30 '17 at 11:54
  • Fair enough, so the only code that's included in your question is a 3-liner where you are sure that it's not the problem. As said, I can't comment the technical details, only make sure that the basics are not at fault. So how about you store the `AsyncOperation` somewhere just to ensure that its `isDone` property is really set at the time you think it is. – grek40 Jan 30 '17 at 12:05
  • Is it possible to Load your scene without the async, just to see if the SceneObjects become active in that case? – Fredrik Schön Jan 31 '17 at 14:37
  • Also, have you read this? https://forum.unity3d.com/threads/unet-with-additive-scene-loading-and-different-scenes-for-each-client.383468/ – Fredrik Schön Jan 31 '17 at 14:42
  • @Fredrik i didn't read it completely but i used its code snippet as i mentioned in my question. did you find any thing in usual in my code? – Muhammad Faizan Khan Feb 01 '17 at 04:42

2 Answers2

2

Late to the party here, but I ran into this as well and came up with my own solution here:

https://gist.github.com/kristianpd/485fd7d78512a22a80117a2d22664185

The core of the problem is that the SceneId's are re-used on NetworkIdentitys and when you load another scene, it will conflict with current NetworkIdentity.sceneIds.

For a little more context on the solution, this forum post is where I walk through a few different attempts before coming to this solution.

https://forum.unity.com/threads/additive-scene-loading-with-unet-conflicting-sceneids-on-scene-objects.525410/#post-3545410

Kristian PD
  • 2,705
  • 1
  • 19
  • 22
1

Did you ever solve this?

My guess would be that you need to wait for all clients to be 'Ready' (scene load finished) before calling SpawnObjects.

Xelnath
  • 65
  • 8
  • Thanks for you commens, but this not the place the right place:). I didn't solve this problem yet. Still willing its solution. Yes i have tried this, did you check my code? – Muhammad Faizan Khan Feb 08 '17 at 04:24