Photon Networking Unity AllProperties is not installed

I started using Photon Networking for Unity and I had a problem. I want to add to CustomProperties in the player, and then I want to debug the result. However, the debug prints are "Null." I do this after creating the room.

The funny thing is that in OnPhotonPlayerPropertiesChanged()it it prints “changed” and does this only at runtime SetPlayerPosition().

But if I then verify that the key inside customproperties does not contain it, so it does not print "10"?

    void Awake()
    {
        SetPlayerPosition();
    }

    public override void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
    {
        Debug.Log("changed");
        if (PhotonNetwork.player.CustomProperties.ContainsKey("1"))
        {
            Debug.Log("it works");
        }
    }

    void SetPlayerPosition()
    {
        ExitGames.Client.Photon.Hashtable xyzPos = new ExitGames.Client.Photon.Hashtable();
        xyzPos.Add(1, "10");
        xyzPos.Add(2, "5");
        xyzPos.Add(3, "10");
        PhotonNetwork.player.SetCustomProperties(xyzPos);
        // PhotonNetwork.player.SetCustomProperties(xyzPos, null, true); doesnt work either
    }
+4
source share
2 answers

Actually the awning consists that keys should be lines!

0
source

PUN doc-api :

void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps) 
{
    PhotonPlayer player = playerAndUpdatedProps[0] as PhotonPlayer;
    Hashtable props = playerAndUpdatedProps[1] as Hashtable;

    Debug.Log(string.Format("Properties {0} updated for player {1}", SupportClass.DictionaryToString(props), player);
    if (player.CustomProperties.ContainsKey("1"))
    {
        Debug.Log("it works 1");
    }
    if (props.ContainsKey("1"))
    {
        Debug.Log("it works 2");
    }
}
+2

Source: https://habr.com/ru/post/1684805/


All Articles