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

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

Join Us
on Discord

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

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.

Need help with Hashtables

2020-12-18 18:06:18

Can't get why

gives me "NullReferenceException: Object reference not set to an instance of an object" error on the last line.
At the same time Hashtable tempHash = new Hashtable();
tempHash.Add("ReadyState", false);
tempHash.Add("ReadyCounter", 0);
tempHash.Add("Start", false);
PhotonNetwork.LocalPlayer.SetCustomProperties(tempHash); and Debugging each of these properties with "(bool)PhotonNetwork.LocalPlayer.CustomProperties["ReadyState"]" e.g. works perfectly fine.
Do I miss something obvious?
The funny thing that I had the same problem recently, and fixed it somehow, but didn't get how exactly, it was 5 A.M. then :lol:
Help :C


2020-12-19 17:44:19

Well, probably i should mention that the working code placed in callbacks, ant the one that doesn't work is in Start function. Maybe there is a problem?

2020-12-19 18:16:43

Okay, I moved the code to the other script where it works and now can't set the player properties.
Here are valueable parts of code:



Sorry for giving too much code, but I'm not sure where exactly I'm making a mistake.
The problem is that in the "RoleAssignment" function Debug says the nickname correct, which means that i accessed the proper player. Bu then it says that he is a Slave according to his hash which is a default value from the first part of the code. It makes me think that I can't change the player properties by "PhotonNetwork.CurrentRoom.GetPlayer(rand + 1).SetCustomProperties(hash);". How then I supposed to do that? Previously I only changed the properties of PhotonNetwork.localPlayer? and it worked fine.

2020-12-21 10:23:53

Hi @Moses,

Thank you for choosing Photon!

By default, setting properties for actor or room properties will not take effect on the sender/setter client (actor that sets the properties) immediately when joined to an online room unlike what it used to be in PUN Classic. Now, instead, the sender/setter client (actor that sets the properties) will wait for the server event PropertiesChanged to apply/set changes locally. So you need to wait until OnPlayerPropertiesUpdate or OnRoomPropertiesUpdate callbacks are triggered for the local client in order to access them. The new behaviour is due to the introduction of the new room option flag roomOptions.BroadcastPropsChangeToAll which is set to true by default. The reason behind this is that properties can easily go out of synchronization if we set them locally first and then send the request to do so on the server and for other actors in the room. The latter might fail and we may end up with properties of the sender/setter client (actor that sets the properties) different locally from what's on the server or on other clients. If you want to have the old behaviour (set properties locally before sending the request to the server to synchronize them) set roomOptions.BroadcastPropsChangeToAll to false before creating rooms. But we highly recommend against doing this.


Back to top