PhotonNetwork.Instantiate not instantiating GameObject locally.

Options
I'm having a very strange issue while using PUN2. I am instantiating a player, however it's only created on other clients and not locally.

While debugging I see that I do indeed get the reference back var gob = PhotonNetwork.Instantiate (gob in this case). so i'm assuming it's getting created locally, but then deleted.

This is all happening right after a asynchronous scene load. I chose to roll my own Scene syncing, so maybe this is part of the issue.

Comments

  • meatloaf
    Options
    I have just confirmed that it is indeed creating locally but then immediately getting destroyed. Not sure why this would be happening.
  • meatloaf
    Options
    This is starting to look a lot like a bug to me. Is there a reason why Photon might destroy a GameObject on scene load locally?
  • meatloaf
    meatloaf
    edited October 2018
    Options
    Ok I think i figured the issue out here.

    I was doing something like this
           var loadingScene = SceneManager.CreateScene(LOADING_SCENE_NAME);
           SceneManager.SetActiveScene(loadingScene);
           SceneManager.LoadSceneAsync(sceneToLoad, LoadSceneMode.Additive);
            
           async.allowSceneActivation = false;
            while (async.progress < 0.9f) {
                onProgressUpdate?.Invoke(async.progress);
                yield return null;
            }
           PhotonNetwork.IsMessageQueueRunning = false;
           async.allowSceneActivation = true;
            //destination scene script Awake() / Start() / ... happen here (my Instatiation in Awake for example)
            while (!async.isDone) {
                yield return null;
            }
           PhotonNetwork.IsMessageQueueRunning = true;
           //this line below was the problem
           SceneManager.UnloadScene(LOADING_SCENE_NAME);
           SceneManager.SetActiveScene(destinationScene);
    

    Essentially the Awake / Starts for all the scripts of the destination scene were being called. Any Instantiations from the scripts on the destination scene at that point were being thrown under the Loading scene since the destination scene technically wasn't done loading. I then unload the loading scene so all the instantiations get lost.

    To fix the issue I instead just merge the LoadingScene with the destination scene instead of unloading the LoadingScene.

    Example
            SceneManager.SetActiveScene(destinationScene);
            SceneManager.MergeScenes(loadingSceneInfo.First,destinationScene);