Custom Properties, Unity, Object refence not set to an instance of an object
Options
Bürküt
✭
when I control player on masterClient İ get no erros but n the other player that line I marked gives nullreferenceexception
bool startTimer = false; double timerIncrementValue; double startTime; [SerializeField] double timer = 20; ExitGames.Client.Photon.Hashtable CustomeValue; void Start() { if (PhotonNetwork.IsMasterClient) { CustomeValue = new ExitGames.Client.Photon.Hashtable(); startTime = PhotonNetwork.time; startTimer = true; CustomeValue.Add("StartTime", startTime); PhotonNetwork.CurrentRoom.SetCustomProperties(CustomeValue); } else { startTime = double.Parse(PhotonNetwork.CurrentRoom.CustomProperties["StartTime"].ToString()); //ERROR LINE****** startTimer = true; } } void Update() { if (!startTimer) return; timerIncrementValue = PhotonNetwork.time - startTime; if (timerIncrementValue >= timer) { //Timer Completed //Do What Ever You What to Do Here } }
0
Comments
-
Hi @Bürküt,
Thank you for choosing Photon!
"StartTime" custom room property is not available when joining the room.
It will be available once set by the master client.
When the master client sets this property, it will send a request to the server, then the server will send an event to joined clients to tell them about the new property update.
So you need to wait until clients are ready and have the "StartTime" property.
There is a callback for that: "IInRoomCallbacks.OnRoomPropertiesUpdate".
PUN provides a utility script CountdownTimer that also uses the same "StartTime" room property key and the same logic as this. So you could take a look at its code: "Assets\Photon\PhotonUnityNetworking\UtilityScripts\Room\CountdownTimer.cs"1 -
Hi @Bürküt,
Thank you for choosing Photon!
"StartTime" custom room property is not available when joining the room.
It will be available once set by the master client.
When the master client sets this property, it will send a request to the server, then the server will send an event to joined clients to tell them about the new property update.
So you need to wait until clients are ready and have the "StartTime" property.
There is a callback for that: "IInRoomCallbacks.OnRoomPropertiesUpdate".
PUN provides a utility script CountdownTimer that also uses the same "StartTime" room property key and the same logic as this. So you could take a look at its code: "Assets\Photon\PhotonUnityNetworking\UtilityScripts\Room\CountdownTimer.cs"
Thanks @JohnTube
Can I use that way to make waves in game? Like a few seconds of waiting than a fight between players for another seconds and waiting again and repeat this for a few times? Is it possible by using this script?0