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! Your search result can be found below. Plus, we offer support via 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.

Problem with Room.SetCustomProperties not working

ACBS
2021-07-30 01:18:55

I've been trying to update custom properties after a room is created and having trouble. SetCustomProperties does not seem to return a value and when debugging cannot be stepped into. If I remove virtual from the definition of SetCustomProperties, I can step into the function but it does not fix the problem. In the example below, all the print statements up to "set id for lobby" will print and the last two print statements will not print.

By default, the room is created with the custom property "id" equal to 0 and any players that join will see the default id and not the updated one. If anyone has insight into this problem it would be appreciated.

Comments

JohnTube
2021-07-30 10:33:42

Hi @ACBS,

Thank you for choosing Photon!

Are you sure you are in a room and that PhotonNetwork.CurrentRoom is not null? Make sure you are joined to a room first; wait for OnJoinedRoom callback or PhotonNetwork.InRoom to be true.
There are no exceptions or errors in console?

You said:

In the example below, all the print statements up to "set id for lobby" will print and the last two print statements will not print.

But in the code snippet there are 3 print calls so if the last two will not print it means only first one will work.
Also you said all print statements up to "set id for lobby", does this mean log message starting with "set id for lobby" is being logged or not?

Are you sure what you posted here matches what you are testing?

ACBS
2021-07-30 22:06:11

I should clarify that in my original post I also print the bool result of SetCustomProperties with a total of 4 print calls and that the "set id" line is getting printed correctly. The lines

did not print at all and even when I call SetCustomProperties without the print I do not see the "after set" line.

I went back and changed the "set id" line to check if the client is InRoom. This is the code with the changed line:

The print result of this code is:

All of this seems pretty normal for a player being in a room but the two lines mentioned in the first block of code do not get printed.

Tobias
2021-08-03 09:42:00

Hamza is on vacation this week.
I'm not sure if print(PhotonNetwork.CurrentRoom.SetCustomProperties(properties));will work. SetCustomProperties returns just a bool. Maybe you have an exception in the log telling you about a failed cast or such?
Call the method and store it's return value into a local variable. Print that.

ACBS
2021-08-03 23:15:44

Thanks for your time.

I've double checked my console and the only notification I get is a warning that the 'dev region' for PUN is 'usw' and not empty which doesn't have much to do with this problem.

I've modified the SetCustomProperties line and the print statement to store the value and print it like so

but the "after set" line still does not print.

There is another thing that might cause problems being that the function that this code is in, GetLobbyInfo, is being called through an event.

GetLobbyInfo is where SetCustomProperties and all the print statements reside and it seems to go into the statement fine. My guesses are that maybe GetLobbyInfo shouldn't be private, there is some interaction where the event doesn't like to call another function past GetLobbyInfo, or that there is some interaction where the event doesn't like calling non-overrided virtual functions.

Theres also the possibility that I've set up the GetLobbyInfo improperly and its' function signature is wrong.

Tobias
2021-08-10 18:00:20

Well, if the "after" debug line doesn't log, it's likely a problem happened in SetCustomProperties or it's not even called at all. A "before" log would help clarify.
You need to be in a room, to set room properties. Not sure if OnLobbyEntered is being called after you joined a room in Photon?

there is some interaction where the event doesn't like to call another function past GetLobbyInfo, or that there is some interaction where the event doesn't like calling non-overrided virtual functions.

This is not likely. If a method can be called as event, this compiles and then works.
If you worry about inheritance issues, simplify your class hierarchy.

Theres also the possibility that I've set up the GetLobbyInfo improperly and its' function signature is wrong.

This is a level of coding at which we can't help. Your code will not compile, if your signature is wrong as event method and this should not be something we have to explain. We won't in any further discussion.

ACBS
2021-08-10 23:41:37

I apologize for the off-topic solutions, the intention was to give more information that could help.

I come with some good news about this problem. I ended up putting the SetCustomProperties code into a coroutine and running that instead.

Once I did this, an error popped up saying something along the lines of

"Write Failed. Custom type not found steamLobby.Id"

I ended up just converting the Id to a string and it works fine; the Id gets set properly and the other players can see it. The only weird aspect I found was that the error didn't show up when it was inline but did when inside a coroutine.

Thanks for your guys' help on this!

Tobias
2021-08-12 16:24:05

What type does the SteamLobby.Id have?

Yes, odd this didn't show up before. I will try to find out why.

ACBS
2021-08-12 20:56:12

The type of the Id is a SteamId struct but it has an implicit conversion to ulong

Tobias
2021-08-13 14:18:14

Ah, I see.
We don't support uLong in PUN directly, so it could not be sent.
That explains the cause but not why it was hidden. I'll get to that in a while (may take a bit, as I'm on vacation next week).

ACBS
2021-08-25 22:53:24

After a bit of digging, I think I found the reason why the error wasn't printing. I ran into a similar problem with something else where the error also did not print out.

SetCustomProperties and my other problem was being run by Facepunch Steamwork's async task. It turns out that async tasks may not catch exceptions so I implemented what was found on this page
https://wiki.facepunch.com/steamworks/Debugging
to fix the other problem and found that it was also causing the error not to print on SetCustomProperties.

Back to top