OnPlayerPropertiesUpdate and OnRoomPropertiesUpdate called before OnJoinedRoom (PUN2)

Hello

I'm surprised to notice that when joining a room we are getting the OnRoomPropertiesUpdate and OnPlayerPropertiesUpdate callbacks before OnJoinedRoom and OnCreatedRoom. Is this intended? It means I'm getting "updates" for things I don't know exist yet.

I suppose I can handle this by simply ignoring updates for unknown players or rooms, but it's not very clean as it means sometimes I might be ignoring bugs...

Edit: the way I fixed it is by exiting early in the properties callbacks if PhotonNetwork.InRoom is false.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @olistan,

    Thank you for choosing Photon!

    What PUN2 version do you use?
    Does this happen when using offline mode or when connected?
    If connected, do you connect to Photon Cloud or Photon Server?

    Do you reproduce this all the time?
    Do you have minimal steps that have 100% chance to reproduce this?

    We are interested in investigating this and fixing it.
  • Hi JohnTube,

    I'm using v2.7.
    It happens when connected to the Photon Cloud.
    100% reproductible.

    Here's a simplified version of my code which should reproduce the problem. I have written the functions in the order they are called.

    using ExitGames.Client.Photon;
    using Photon.Pun;
    using Photon.Realtime;
    using System.Collections.Generic;
    using UnityEngine;

    public class PhotonPun2NetworkMgr : MonoBehaviourPunCallbacks, IPunObservable, IOnEventCallback
    {
    public override void OnEnable()
    {
    base.OnEnable();
    gameObject.AddComponent< PhotonView >();
    }

    public void Start()
    {
    Connect();
    }

    public void Connect()
    {
    PhotonNetwork.ConnectUsingSettings();
    PhotonNetwork.GameVersion = "0";
    }

    public override void OnConnectedToMaster()
    {
    Debug.Log("Connected to master Photon server. Now joining the default lobby.");
    PhotonNetwork.JoinLobby();
    }

    public override void OnJoinedLobby()
    {
    Debug.Log("Joined Photon lobby.");
    PhotonNetwork.LocalPlayer.NickName = name;
    SetPlayerProperty(PhotonNetwork.LocalPlayer, PLAYER_PROPERTY_READY_TO_GO, false);
    SetPlayerProperty(PhotonNetwork.LocalPlayer, PLAYER_PROPERTY_SYNCHRO_POINT, 1);
    CreateRoom("test", 1);
    }

    public void CreateRoom(string name, int gameMode)
    {
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable();
    roomOptions.CustomRoomProperties.Add(ROOM_PROPERTY_GAMEMODE, gameMode);
    roomOptions.CustomRoomPropertiesForLobby = new string[] { ROOM_PROPERTY_GAMEMODE };
    roomOptions.IsOpen = true;
    roomOptions.IsVisible = true;
    roomOptions.MaxPlayers = 6;
    roomOptions.PlayerTtl = 0;
    roomOptions.SuppressRoomEvents = false;
    PhotonNetwork.CreateRoom(name, roomOptions);
    }

    public override void OnRoomPropertiesUpdate(ExitGames.Client.Photon.Hashtable propertiesThatChanged)
    {
    Debug.Log("Photon OnRoomPropertiesUpdate.");
    }

    public override void OnPlayerPropertiesUpdate(Player photonPlayer, ExitGames.Client.Photon.Hashtable changedProps)
    {
    Debug.Log("Photon OnPlayerPropertiesUpdate.");
    }

    public override void OnCreatedRoom()
    {
    Debug.Log("Photon room has been created.");
    }

    public override void OnJoinedRoom()
    {
    Debug.Log("Photon room has been joined.");
    }

    // --- IPunObservable implementation ---

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
    // Not sure if needed.
    }

    private const string PLAYER_PROPERTY_READY_TO_GO = "g";
    private const string PLAYER_PROPERTY_SYNCHRO_POINT = "s";

    private const string ROOM_PROPERTY_GAMEMODE = "gm";

    private void SetPlayerProperty(Player player, string key, object value)
    {
    s_tmpHashtable.Clear();
    s_tmpHashtable.Add(key, value);
    player.SetCustomProperties(s_tmpHashtable);
    }

    private void SetRoomProperty(Room room, string key, object value)
    {
    s_tmpHashtable.Clear();
    s_tmpHashtable.Add(key, value);
    room.SetCustomProperties(s_tmpHashtable);
    }

    private static ExitGames.Client.Photon.Hashtable s_tmpHashtable = new ExitGames.Client.Photon.Hashtable();
    }
    In this case with a single master client creating a room, OnPlayerPropertiesUpdate() isn't called, but it is called on the client that joins the room later.
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited March 2019
    Hi @olistan,

    Thank you for your report!
    I have managed to reproduce.
    Current manual fix is to remove the line 1686 from LoadBalancingClient.cs (PUN 2.7).
  • @JohnTube I am also using 2.7 from the Unity Asset store. I'm kind of a newb at Photon, so I'm glad that @olistan was able to make a quick repro.

    Real quick: Where is LoadBalancingClient.cs located? (there are a lot of folders on PUN)

    And thanks @olistan

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited March 2019
    Hi @Breeman,

    Thank you for choosing Photon!

    LoadBalancingClient.cs is located under "Assets/Photon/PhotonRealtime/Code"

    The fix in this post is for OnPlayerPropertiesUpdate being called while it shouldn't be.
    There is also a fix for when OnRoomPropertiesUpdate being called while it shouldn't be:

    Replace lines 1646 of LoadBalancingClient.cs:
    this.InRoomCallbackTargets.OnRoomPropertiesUpdate(gameProperties):
    with:
     if (this.InRoom)
                    {
                        this.InRoomCallbackTargets.OnRoomPropertiesUpdate(gameProperties);
                    }
    Both fixes will be added to next version (2.8)
  • Thanks for taking care of this @JohnTube .
    No problem @Breeman ;)
  • JohnTube
    JohnTube ✭✭✭✭✭
    This issue has been fixed in PUN 2.8.
  • Thanks for the heads up @JohnTube !
    The changelog only mentions OnRoomPropertiesUpdate. Has OnPlayerPropertiesUpdate been fixed too?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited April 2019
    Yes yes. it was forgotten in the changelog/versionhistory. We will add it.
  • Great, thanks :).
  • hi, i have also OnRoomPropertiesUpdate called 2 times when i create a room without touching to the setCustomProperties. Tho i have downloaded photon in april. What does it mean ?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @antigode,

    Make sure you have updated to latest PUN by checking the version in PhotonNetwork.PunVersion or in the PhotonServerSettings asset inspector.

    If it's the latest make sure you are not setting properties after room creation.
    What are the changed properties in each OnRoomPropertiesUpdate call?
  • Yes this is the PUN 2.9 version and in the call there is only a debug.log for now ! I'm investigating
  • Hi. It so strange, but lastest PUN version has 2.41 in Asset Store. How i can download new version?

  • He probably mistyped it but the latest version is 2.41

  • It is two.fortyone. This is newer than two.nine (from 2019).

  • Oh, i'm sorry, it's true, i just using to the fact that 2.9 is written as 2.09))

  • Please update.