PhotonNetwork.CurrentRoom keeps returning null, even when CreateRoom() succeeded

Options
Hey there fellow creators, I'm quite a beginner with Photon PUN2, so don't shoot me if this is basic, but I've been sitting at this problem for a few days now, and I can't really come out of it, so I'd really appreciate if anyone could help me out. I've created a lobby system in which players can create a Room by choosing a name for the room, and choosing a level. Now after a player selects the level, the room is created, and a character selection panel shows up. I need to make sure that no more than 1 player can select the same character. I implemented this by adding custom room properties to my room when creating it. For every character available, I made a custom property with the name of the character as the key, and then a boolean value which says if the character is still available (initially they are all available thus set to true). Now when I create the room, everything seems to be fine, because I check if(PhotonNetwork.CreateRoom(room_name, room_options)), and this always evaluates to true, OnJoinFailed() is never called, even though everywhere where I try to access the PhotonNetwork.CurrentRoom property, it returns null. It's so weird, everything looks like I'm in the room, the character selection opens as planned, I can call LeaveRoom() (which I guess should give a problem if you're not currently in a Room), but PhotonNetwork.InRoom returns false and PhotonNetwork.CurrentRoom returns null. I really need to access this property since I need to get access to the CustomProperties of the current room to see which characters are already taken by other players. Could anybody help me out? Thanks a lot!

Comments

  • S_Oliver
    S_Oliver ✭✭✭
    edited April 2020
    Options
    Use the callbacks to determine if your in a room or not(OnJoinedRoom e.g), could you post your code ?
  • BigGameCo
    Options
    there's some more events you could put in to get more clues to what the problem might be. OnJoinedRoom, OnCreateRoomFailed etc. I don't think putting the CreateRoom inside the if statement will actually indicate whether or not the room was created - that's what the events are for.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @ChuppaFlow,

    Thank you for choosing Photon!
    if(PhotonNetwork.CreateRoom(room_name, room_options))
    
    The if check here does not mean the room creation is successfully, it simply means the client enqueued the room creation request to be sent to the server (conditions & pre-checks validated & client connected).

    As @S_Oliver and @BigGameCo already mentioned you need to implement callbacks since all Photon operations are asynchronous requests from client to server and expect response from server and sometimes a single client method will result in a rather 'complex / long' process of multiple requests and even switching servers.
    So I would implement OnJoinedRoom and OnCreateRoomFailed for this case like @BigGameCo suggested.