Pun2 CustomProperties coming null

Im getting the NullReferenceException error telling me im not setting somewhere and I'm having alot of trouble figuring it out.. so as the player joins the room i set properties for the local player with cached values from PlayFab(User Statistics) and im trying to share these values in a room. Once the room is full(two players) im setting a local variable like this, RemotePlayer = PhotonNetwork.LocalPlayer.GetNext(); , then taking that RemotePlayer and passing it into this function.
public void SetEnemyInfo(Player _player)
    {
        Player player = _player;
        _enemyPlayerName.text = (string)player.CustomProperties["PlayerName"];
        _enemyPlayerWins.text = "" + (int)player.CustomProperties["Wins"];
        _enemyPlayerRating.text = "" + (int)player.CustomProperties["Rating"];
    }
when the room is full this is called

    private void SetOtherPlayer()
    {
        EnemyListing.Instance.SetEnemyInfo(RemotePlayer);
    }
My error is occuring on the "Wins" line however the player name doesn't post either. Im doing this method the exact same for the local player only using the LocalPlayer built in variable(works fine). The SetEnemyInfo method even works for the second player joining but not the first player in the lobby.

I may be trying to make this way more complicated than this needs to be but if I could receive some guidance I'd be grateful

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @LucaBrasi,

    Pun2 CustomProperties coming null
    The discussion title does not correspond to the issue described in the post.

    NullReferenceException error
    You can learn to debug this. You need to know at least which line and what is null exactly. Then you can try to find out why.

    Some other notes:
    1. There is already Player.Nickname, why do you add "PlayerName" custom property?
    2.
    i set properties for the local player with cached values from PlayFab(User Statistics)
    This is nice but are you sure you are caching/setting the properties before trying to access them. When and how do you do this? can you show us the code?
    3.
    My error is occuring on the "Wins" line
    Make sure you are using the same property key string. It's recommended to use 'global' constant strings and shorter strings for those.
    4.
    My error is occuring on the "Wins" line however the player name doesn't post either
    PlayerName custom property could be an empty string.
    5. Use some helper or extension methods to either TryGet a custom typed property by name OR get a customer property if any or a default value by type. Use those helper methods to access custom properties and to log errors etc.
    6. Implement IInRoomCallbacks.OnPlayerPropertiesUpdate to know when custom player properties change after joining the room.

    I think the issue is either;
    A. "Win" and other custom properties are not set at all when joining the room: not cached before joining the room
    B. custom properties not set properly (some are set others are not, wrong key strings)
    C. custom properties are set post room join/creation and not received yet. See 6 above.
  • Okay I have alot of messy code so I just had to work that out and I realized I'm trying to get the values in override OnPlayerEnteredRoom so they aren't set yet because i set them in override OnJoinedRoom(), so try to set them in OnPlayerPropertiesUpdate? Do you think you could explain this callback to me a little bit and maybe a simple application of it? I tried researching it before this reply but I can't seem to find anything to help me for punv2.
    As far as I can see this is the syntax
    public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
    {

    }
    However, OnPlayerPropertiesUpdate has a red line under it saying I there is no method to override. Im inheriting from : MonoBehaviourPunCallbacks, IInRoomCallbacks {.

    Thank you for your relpy @JohnTube, idk why im letting pun kick my ass. lmao
  • bump ^