The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

CustomProperties on current room players not correct for new players entering the room

eligolf
2021-11-10 17:39:06

Hi,

I have a problem with setting and getting custom properties on players. So far I am able for the current players in the room to get the correct info from other players properties. The problem is that new players don't seem to get the updated property values that was changed on players in the room before they entered the room.

More specifically I am trying to create a player list in my room and all have to press "ready" for master to be able to start the game. All players have an image next to their name in the player list to let people know who is ready and who is not.

When a player presses Ready button the function below runs on all players in the room.

Where _listings holds all player listing items and each listing is connected to a specific player. When a player enters the room I run the following function locally, going through all players in PhotonNetwork.CurrentRoom.Players and adding each one with this function:

In SetPlayerInfo is where I find all players properties and this is where it doesn't detect the players CustomProperty which was set before a player joined:

All players now go into the else statement no matter if they previously set themselves to ready.

Do I need to do something special for new players entering the room to take part of the already entered players updated properties?

Comments

JohnTube
2021-11-11 04:00:17

Hi @eligolf,

I'm sorry to say that you are tried to reinvent the wheel as you missed how custom properties should be used properly.

Instead of using RPCs to set them you should use SetCustomProperties methods instead and wait for callbacks OnPlayerPropertiesUpdate or OnRoomPropertiesUpdate. Never set methods directly via CustomProperties Hashtable, use it only to read values.

eligolf
2021-11-11 05:06:16

Hi,

Thanks for the reply, I get what you are saying and I will probably rewrite the code to fit that after googling around for some time.

The question still stands though, how do new players that enteres the room get the previously changed CustomProperties from players already in the room? The custom properties doesn't seem to update for the new player entering, only the ones already in the room.

JohnTube
2021-11-11 05:13:21

Hi @eligolf,

Please use player.SetCustomProperties method and you will see that it works as expected.

This is all done internally for you in client SDK under the hood so you don't worry about it.

But here are a few notes (I can go into further deeper details if you need):

For every remote player joins the room there is a Join event broadcast which contains the properties of that joiner (unless you create rooms with roomOptions.SuppressRoomEvents).

When local player joins the room the Join operation response contains the list of actors already joined with their respective properties

eligolf
2021-11-11 10:37:39

Thanks John, it works great now! You are a life saver.

Back to top