Problem with Room.SetCustomProperties not working

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.
ExitGames.Client.Photon.Hashtable properties = curRoom.CustomProperties;
print("before adding id");
properties["id"] = steamLobby.Id;
print("set id for lobby-------------------" + steamLobby.Id + curRoom.Name + PhotonNetwork.CurrentRoom.Name);
print(PhotonNetwork.CurrentRoom.SetCustomProperties(properties));
print("after set custom prop-------------------------------------------");

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    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?
  • 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
    print(PhotonNetwork.CurrentRoom.SetCustomProperties(properties));
    print("after set custom prop-------------------------------------------");
    
    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:
    print("before adding id");
    properties["id"] = steamLobby.Id;
    print("set id for lobby-------------------" + steamLobby.Id + curRoom.Name + PhotonNetwork.InRoom);
    print(PhotonNetwork.CurrentRoom.SetCustomProperties(properties));
    print("after set custom prop-------------------------------------------");
    

    The print result of this code is:
    before adding id
    set id for lobby-------------------109775241009782960DD Room 643True
    
    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.


  • 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.
  • 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
    bool setProp = PhotonNetwork.CurrentRoom.SetCustomProperties(properties);
    print("after set custom prop-------------------------------------------" + setProp);
    
    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.
    Steamworks.SteamMatchmaking.OnLobbyEntered += GetLobbyInfo;
    
    //This is part of the Facepunch Steamworks Wrapper
    //The defintion for OnLobbyEntered is:
    public static event Action<Lobby> OnLobbyEntered;
    
    //And the definition for GetLobbyInfo is:
    private void GetLobbyInfo(Steamworks.Data.Lobby lobby)
    
    
    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.
  • 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.
  • 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.
    private IEnumerator SetCustomProperties()
    {
       yield return new WaitForSeconds(1);
       //All the SetCustomProperties code from before
    }
    

    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!
  • What type does the SteamLobby.Id have?

    Yes, odd this didn't show up before. I will try to find out why.
  • The type of the Id is a SteamId struct but it has an implicit conversion to ulong
    public struct SteamId
        {
            public ulong Value;
    
            public uint AccountId { get; }
            public bool IsValid { get; }
    
            public override string ToString();
    
            public static implicit operator SteamId(ulong value);
            public static implicit operator ulong(SteamId value);
        }
    
  • 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).
  • 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.