How you properly leave a Photon team?


When I click the leave room button, which goes back to the title menu, the player leaves. But when the player returns to the same room, I get console message that player already has a team.

When I add: PhotonNetwork.LocalPlayer.LeaveCurrentTeam() to the leave button. I get an error most of the time saying that PhotonView has been destroyed. Maybe there is something I'm missing.


  • Fauyeti

    Okay I can reliably recreate the error. After the room menu, if you join a the Game scene and hit the Unity engine stop button and start another game up, create a room, and try and leave the room. It'll give me the error that Photon view has been destroyed and I'm still trying to access it.

    If I make a change to a script (forcing it to recompile and everything), the problem will go away only for me to recreate it like I said above.

  • Fauyeti

    I could really use any sort of help. Let me know if anyone needs anymore information. I haven't made much progress. For some reason when I click stop on my unity editor it gives me an error where something is still trying to access a photon view...and I really have no idea where from. I'm going through everything looking for photon views and temp removing them to see if I can get a change.

  • Tobias
    Tobias admin
    edited March 2023

    The Team of a player is stored in the Custom Player Properties. When set correctly, they are cached locally and carry over to the next room.

    PhotonTeamsManager.ClearTeams() is being called when the client leaves the room but does not clean up these properties for you.

    The LocalPlayer.CustomProperties should not be directly changed while you are in a room but you can set them before you join a room (or e.g. when you left). Simply remove the player's team property. The key string is defined here: PhotonTeamsManager.TeamPlayerProp.

    About accessing the PV: Is there no callstack for this? Would help a lot to know which code accesses an old PhotonView.