Search Unity

** CAN'T FIGURE OUT Player Custom Properties **

Discussion in 'Multiplayer' started by Peteroid69, Feb 9, 2022.

  1. Peteroid69

    Peteroid69

    Joined:
    Nov 11, 2018
    Posts:
    36
    HI! ... the following class is attached to an empty object in a scene... when the Start() runs (upon entering a PHOTON Room via LoadLevel of the scene)... it seems the "Tag" is NOT setup to "value"... and is just blank (not sure if it is ""):
    .
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Photon.Pun;
    using Hashtable = ExitGames.Client.Photon.Hashtable;

    public class TestCustomProperties : MonoBehaviourPunCallbacks
    {
    void Start()
    {
    Hashtable hash_in = new Hashtable();
    hash_in.Add("Tag", "value");
    PhotonNetwork.LocalPlayer.SetCustomProperties(hash_in);

    string tag_value = (string)(PhotonNetwork.LocalPlayer.CustomProperties["Tag"]);

    Debug.Log("Tag Value = " + tag_value); // tag_value is BLANK!
    }
    }

    the result of the Debug.Log() line is:
    .
    Tag Value =
    .
    any idea what is wrong?
     
    Last edited: Feb 9, 2022
  2. Peteroid69

    Peteroid69

    Joined:
    Nov 11, 2018
    Posts:
    36
    ok... figured something out... it takes TIME for the Custom Properties to take effect after SetCustomProperties.... is there a way to know when this happens (like a callback?)
    .
    the reason i know this is i also put the:
    .
    string tag_value = (string)(PhotonNetwork.LocalPlayer.CustomProperties["Tag"]);
    Debug.Log("Tag Value = " + tag_value); // tag_value is BLANK!
    .
    in the Update method.. and the 5TH time it did Update the Tag was indeed set to 'value'....
     
  3. Peteroid69

    Peteroid69

    Joined:
    Nov 11, 2018
    Posts:
    36
    so... my (kind of odd solution) is to have a CustomProprties Key i setup via SetCustomProperties called "Valid"... then set it to "yes"... and poll to see if "Valid" = "Yes" and then i will know it has been updated...
     
  4. Peteroid69

    Peteroid69

    Joined:
    Nov 11, 2018
    Posts:
    36
    does anybody know a means to tell when the values of a SetCustomProperties action actually go into effect?... like a OnCustomPropertiesUpdated()?... having the old values stay in place for multiple Updates() is a bit annoying.... :)
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    They are updated by the server (basically confirming them), by default.
    Have a look at the doc for a summary of how to use them and the callbacks.

    The paragraph "Properties Synchronization" also explains how to get the properties changed immediately, as in PUN Classic (spoiler: set roomOptions.BroadcastPropsChangeToAll to false).
     
  6. Peteroid69

    Peteroid69

    Joined:
    Nov 11, 2018
    Posts:
    36
    thanks!.. i will look up these concepts! :)