OnPlayerPropertiesUpdate / OnRoomPropertiesUpdate are not called
The whole answer can be found below.
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).
OnPlayerPropertiesUpdate / OnRoomPropertiesUpdate are not called
develax
2019-09-29 16:09:23
None of this method is called when calling 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?
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.
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 if RoomOptions.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:
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?
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);
}
Hi @JohnTube,
it works only when connected to the cloud.
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.
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.
Maybe there was a bug on the local server that was fixed on the cloud version.
Check my message.
@JohnTube, thanks!
Back to top