Photon keeps switching scenes back and forth without PhotonNetwork.LoadScene()

Since today, my game started showing this very weird behavior:

I have a Main Menu Scene, and when i click a "Quick Match" button, it calls "JoinRandomRoom" and successfully creates or enter an already created room, calling the PhotonNetwork.LoadScene(), then the player goes to a Scene called "Room" which players can setup their characters before the game actually begins.

But weirdly enough, when a player enters an already created room, it keeps flashing back and forth between the Main Menu and the Room scene, as seen on this video:

https://youtube.com/watch?v=U1_fIxzyFI8

So, I started to investigate what could be possibly be doing this. Currently I have 2 ways of navigating through scenes in the game. A custom class that uses SceneManagement.LoadScene, that doesn't require Photon because the scene navigation is offline (settings, credits, etc), and the PhotonNetwork.LoadScene(), which is the scene loading that is networked. (I currently have PhotonNetwork.AutomaticallySyncScene set to true). I have put Debug.Logs in all scene transitions that are not networked, and I haven't got a single log in the console, so that means that the one who is actually making the scene transition is actually Photon, for some reason.

So, there are 2 possible behaviors that happens:

1- If you enter a room that is already created by another player (you are not the MasterClient), the flicker happens

2- If you are the only one in the room (as the MasterClient), the screen does not flicker, and everything works ""correctly""

Knowing that, i tried to log the Room Custom Properties at the start of the scene, and as they are updated, with the following code (Inside the code that runs in the Room scene):
public override void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged) {
        if (propertiesThatChanged.ContainsKey("curScn")) {
            Debug.Log("Current scene is now " + propertiesThatChanged["curScn"]);
        }
    }

And the log result is the following:

utPcplz.png

Do any of you know what could be possibly happening? For some reason Photon is pulling me back and forth between Main Menu and Room

OBS: the log above was made by entering a room with a single client, no other client was in the room, so all the code was being run """"locally"""" (without interference from other clients)

Comments

  • Check which script is running the "load scene" code and which conditions there are. If it's in Start() you may load the script with the scene, it runs and will load again.
    Debug.Log it like you do with the OnRoomProperties update but for the actual loading.
  • After checking my code, i can confirm that no "PhotonNetwork.LoadLevel()" is running on a Start method.

    I even ran a Find with the string "PhotonNetwork.LoadLevel" to see all references of it on my project, and of the 5 that exists, only one happens before the game starts (after the main menu and Room scenes)

    unknown.png

    Going one by one reference:

    JoinedRoomCallback.cs(42): Is the one on the print, the Photon Callback that sends the player to the Room scene after joining a room

    KambojaManager.cs(196): This object only exists in the game, and this is called in the end of the game, leading to the post game scene (where the scores are shown)

    PostGameManager.cs(199): After the scores are shown, this code makes players go back to the Room scene (this is only called after the game has already finished)

    RoomManager.cs(725): This is called in the room when all players are ready and the room leaders starts the game.

    No other references are found, and there is no code that sends the player back to the Main Menu after entering the room scene.

    Is there any possibility of some kind of cache being saved and sending the Main Menu scene to the client?
  • At the moment, I don't really have an idea how this happens.

    As your code/log above shows that the room property for "curScn" gets changed again and again, let's see why / how.
    It is set in PhotonNetwork.SetLevelInPropsIfSynced(). I would add debug log there to figure out why this changes. The callstack should expose that.
  • I have to say, this seems really similar to my recent issue in another thread:
    https://forum.photonengine.com/discussion/18495/setting-isvisible-to-true-kicks-non-master-players#latest

    Similarities:
    1. Scene reloads for non-master clients when room properties are changed.
    2. Master client is unaffected

    A small difference may be that your room properties are being changed more often than mine are, so I only see the scene reload once while you see it reload repeatedly.

    When I took out any room property updates or room setting updates (like IsVisible and IsOpen), it seemed to work... but of course I need the above to be working.
  • Oddlord
    Oddlord
    edited May 2022

    Hello, I've been experiencing this in our game recently and can't figure out why it's happening.

    I've tried to manually reproduce the bug by changing the room properties as StaticWild suggested, but that doesn't seem to be what's causing the issue.

    To make things worse, this behaviour in our game is extremely flakey and has only occurred to some users. I've seen it happen to them, but I've never been able to reproduce it on my devices (Android tablets), which makes debugging it extremely difficult.

    If anyone has any clue or any update to share, that would be of huge help. Thanks!

  • Hello! Update on my problem with the scene flickering.

    I found out that it was indeed the setting of custom room properties that caused this race condition.

    In our code, we were storing in the room properties a flag to describe whether the voice chat had been enabled or not for a specific player. The race condition manifested if one player toggled the voice chat and at the same time the other player selected a level (triggering a PhotonNetwork.LoadScene()). When this happened, the LoadScene would change the scene for both players, then the update of room properties from the first player would take effect, but the Hashtable that player had at the point of updating it still contained the old value for "curScn", so the old scene is now reloaded, cause that update of room properties is interpreted as a scene change by Photon.

    I fixed it by changing the way we store the voice chat flag, now without using custom room properties.

  • Hello's face the same problem, whenever I change the room property during game, scene is reloading for non master client,is there any solution for it? with using room property update?