How to wait before loading a scene with PUN2 ?

I've been using PUN 1 a lot before and I'm on a new project, trying to switch to PUN 2.

However I seen that PhotonNetwork.LoadLevelAsync() doesn't exist anymore and is replaced by PhotonNetwork.LoadLevel() which is Async but isn't an AsyncOperation.

So I would like to know how could I make all players preload a scene before actually changing to it, like it was possible before by turning asyncOperation.allowSceneActivation to false.

Best Answer

  • Spyco01
    Spyco01
    Answer ✓

    Okay thank you ! And yes that was the solution I found, so I added this to PhotonNetworkPart.cs so I can get access to the private variable _AsyncLevelLoadingOperation and be able to use AsyncLevelLoadingOperation.allowSceneActivation

    public static AsyncOperation AsyncLevelLoadingOperation
            {
                get
                {
                    if (_AsyncLevelLoadingOperation != null)
                    {
                        return _AsyncLevelLoadingOperation;
                    }
                    else
                        return null;
                }
            }
    

Answers

  • There is the private PhotonNetwork._AsyncLevelLoadingOperation. It should possibly be enough to make this accessible and use it?

  • From what I read and understand from the documentation, PhotonNetwork.AsyncLevelLoadingOperation can be used to make a progress bar of the loading, but not to "pause" the loading of the scene.

    It seems like the replacement of asyncOperation.progress, not asyncOperation.allowSceneActivation

  • I may have found a solution, but it requires edit of the PhotonNetwork class. So I have a new question are we allowed to edit classes from PUN ?

  • You can edit it, yes, but we are likely unable to support those changes. If you require support that is even remotely related to your changes, let us know.

    Shouldn't you be able to use AsyncLevelLoadingOperation.allowSceneActivation? I don't know the details, tbh.

  • Spyco01
    Spyco01
    Answer ✓

    Okay thank you ! And yes that was the solution I found, so I added this to PhotonNetworkPart.cs so I can get access to the private variable _AsyncLevelLoadingOperation and be able to use AsyncLevelLoadingOperation.allowSceneActivation

    public static AsyncOperation AsyncLevelLoadingOperation
            {
                get
                {
                    if (_AsyncLevelLoadingOperation != null)
                    {
                        return _AsyncLevelLoadingOperation;
                    }
                    else
                        return null;
                }
            }