PUN cancels an ongoing async level load, as another scene should be loaded. (PLS HELP)

"PUN cancels an ongoing async level load, as another scene should be loaded. Next scene to load: Test" is the error message.

It loads each player into the level except for the master client, although when only one player is in the server (being the master client), it brings the master client through the level perfectly fine with no errors.

I've tried for so long and i still can't figure out why it doesn't work :l



Here is this code:

PhotonView PV;



   private void Start() {

       PhotonNetwork.AutomaticallySyncScene = true;

       PV = GetComponent<PhotonView>();


   }


   private void Update() {

       if (Input.GetKeyDown(KeyCode.P)) {

           if (!PhotonNetwork.IsConnected) return;

           if (!PhotonNetwork.IsMasterClient) return;

           if (PhotonNetwork.CurrentRoom == null || PhotonNetwork.CurrentRoom.Players == null) return;

           PhotonNetwork.LoadLevel("Test");

       }

Best Answer

  • Tobias
    Tobias admin
    Answer ✓

    Make sure the Master Client never creates more than a single instance of this script.

Answers

  • Is there anything suspicious in the log of the Master Client? It will start loading right away, so I don't see how PUN causes the failure.

  • There aren't any errors or weird things in the log, although i have noticed that on the master client, it loads the scene by the amount of players that are in the game. If there were 2 players (including the master client) it would load the intended scene twice on the master client, although it'll just say "Test (Loading)" right after it, and won't stop loading. I've checked quite a few times if the load level code has been ran more than once, but theres only one call for the function. I have no idea how this makes sense and i've been banging my head at my desk for 2 days now :)

  • If the script exists on each character (instantiated per player), then it will run multiple times. On the Master Client, all such scripts will set the property to load a scene (meant to update the others) and will immediately start loading the scene (multiple times, locally)...

  • Luductions
    edited May 2022

    What are you suggesting i do 👀

    I just edited the code so now it adds the script (above) if its the master client. Elsewise, it won't add it at all. I have no idea if this was even meant to do anything but it still leaves to the same effect of running the scene multiple times on the master

  • Tobias
    Tobias admin
    Answer ✓

    Make sure the Master Client never creates more than a single instance of this script.

  • How do i make sure of this? As far as i know, there's only one instance of it.

  • Nevermind i got it now :D

  • There aren't any errors or weird things in the log, although i have noticed that on the master client, it loads the scene by the amount of players that are in the game.

    If there were 2 players (including the master client) it would load the intended scene twice on the master client, although it'll just say "Test (Loading)" right after it, and won't stop loading.

    I've checked quite a few times if the load level code has been ran more than once, but theres only one call for the function.

    I have no idea how this makes sense and i've been banging my head at my desk for 2 days now :)

  • Something like this worked for me. All I did was add a Destroy(this); underneath the PhotonNetwork.LoadLevel to stop the script from trying to load the level over and over.

    I'm still new to Photon so I don't know if this is the proper way to do it. But it worked for me.


    void Win()

      {

        if (PhotonNetwork.IsMasterClient)

        {

          PhotonNetwork.LoadLevel("VictoryE");

          Destroy(this);

        }

      }