OnPlayerPropertiesUpdate / OnRoomPropertiesUpdate are not called

The whole answer can be found below.

Please note: 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! And we offer you support through these channels:

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).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

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

develax
2019-09-29 17:02:38

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.

JohnTube
2019-09-30 10:56:55

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:

"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.

develax
2019-09-30 17:42:38

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?

JohnTube
2019-10-01 10:27:00

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);  
}

develax
2019-10-01 17:56:19

Hi @JohnTube,

it works only when connected to the cloud.

JohnTube
2019-10-02 11:27:54

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.

develax
2019-10-02 16:15:16

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.

JohnTube
2019-10-02 16:17:53

Maybe there was a bug on the local server that was fixed on the cloud version.
Check my message.

develax
2019-10-02 16:51:37

@JohnTube, thanks!

Back to top