OnPlayerPropertiesUpdate / OnRoomPropertiesUpdate are not called
Options
None of this method is called when calling
What could be wrong?
player.SetCustomProperties(prop)
or room.SetCustomProperties(prop)
. They are overridden in the correct way, I hope:
public override void OnPlayerPropertiesUpdate(Player target, ExitGames.Client.Photon.Hashtable changedProps) { Log.WriteMethodName(); base.OnPlayerPropertiesUpdate(target, changedProps); } public override void OnRoomPropertiesUpdate(ExitGames.Client.Photon.Hashtable propertiesThatChanged) { Log.WriteMethodName(); base.OnRoomPropertiesUpdate(propertiesThatChanged); }I found this thread but it's not my case.
What could be wrong?
0
Comments
-
Well, actually they are not called at all only when working with a locally installed Photon server. When the app is connected to the cloud server the
OnRoomPropertiesUpdate()
method is called only once with"curScn"/"Start"
and it's never called again with my properties.
0 -
Hi @develax,
This is expected, known issue if you may.
In PUN2 the client who sets properties will trigger the callbacks only when the server sends the PropertiesChanged event. This event is sent back to the client who sets the properties only ifRoomOptions.BroadcastPropsChangeToAll
is enabled, which is the case by default.RoomOptions.BroadcastPropsChangeToAll
(and all room flags for that matter) are not supported by Photon Server SDK v4.0.29.11263.
As you can read on the documentation page here:"Broadcast Properties Change" option is not available (RoomOptions.BroadcastPropsChangeToAll). The client who calls SetProperties will not receive PropertiesChange event unless CAS is used. CAS is a workaround to have a consistent behaviour between Photon Cloud and Photon Server.0 -
Hi @JohnTube,
I tried to use CAS for a consistent behaviour but the OnRoomPropertiesUpdate() still wasn't called.
First, I set a custom property when creating a room:RoomOptions roomOptions = new RoomOptions { MaxPlayers = 4, CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { CustomProperties.BotsList, new Dictionary[int, object]() } } }; PhotonNetwork.CreateRoom(null, roomOptions);
Then I change this property with CAS by calling this method:public static void AddBotInfoProperty(this Room room, BotInfo botInfo) { Dictionary[int, object] bots = (Dictionary[int, object])room.CustomProperties[CustomProperties.BotsList]; bots.Add(botInfo.Id, botInfo); room.SetCustomProperty(CustomProperties.BotsList, bots, bots); }
and this is my helper method:private static void SetCustomProperty(this Room room, string propName, object propValue, object expectedValue) { ExitGames.Client.Photon.Hashtable prop = new ExitGames.Client.Photon.Hashtable(1) { { propName, propValue } }; ExitGames.Client.Photon.Hashtable oldvalueProp = new ExitGames.Client.Photon.Hashtable(1) { { propName, expectedValue } }; room.SetCustomProperties(prop, oldvalueProp); }
What is missing here?0 -
Hi @develax,
For CAS to work, the expected properties need to match what is currently on the server.
The expected properties should not match the properties to set which is what you are trying to do.
So I would do it like this:public static void AddBotInfoProperty(this Room room, BotInfo botInfo) { Dictionary<int, object> oldBots = (Dictionary<int, object>)room.CustomProperties[CustomProperties.BotsList]; Dictionary<int, object> newBots = new Dictionary(oldBots); newBots.Add(botInfo.Id, botInfo); room.SetCustomProperty(CustomProperties.BotsList, newBots, oldBots); }
0 -
Hi @develax,
I tested CAS on the self-hosted Photon Server and I got the PropertiesChanged event on the client who called the SetProperties operation.
Make sure the operation actually succeeded and the properties changed on other clients or see if you did not get an error.
You can increase the logging level or listen (OnEventCallback) for PropertiesChanged event, code 253.0 -
Hi @JohnTube,
I've subscribed to PhotonNetwork.NetworkingClient.OpResponseReceived and indeed I'm getting an error:opResponse.DebugMessage = "CAS update failed: property='BotsList' has value='System.Collections.Generic.Dictionary`2[System.Int32,System.Object]'"
But it happens only on the local Photon Server, there are no errors when connected to the cloud. So, I'm confused.0 -
Maybe there was a bug on the local server that was fixed on the cloud version.
Check my message.1