Quantcast
Channel: Recent Discussions — Photon Engine
Viewing all articles
Browse latest Browse all 15755

CustomProperties crash?

$
0
0
Hello, when I call something like this:
int ai = (int) PhotonNetwork.playerList[index].CustomProperties["avatarIndex"];
...I'm getting a crash (well, a NullReferenceException) if the "avatarIndex" property doesn't already exist. Essentially it's returning null and it's crashing trying to convert to a non-nullable type. Is there a better way to do this?

I realise I could code it as:
Object ob =PhotonNetwork.playerList[index].CustomProperties["avatarIndex"];
int ai = (ob == null) ? 0 : (int) ob;
But that's quite a mouthful every time I want to access the data. I guess I could also pre-initialise the customProperties too, but I wondered if you were aware of the crash?

Viewing all articles
Browse latest Browse all 15755

Trending Articles