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.

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

ChuppaFlow
2020-04-11 18:19:14

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
2020-04-11 20:53:27

Use the callbacks to determine if your in a room or not(OnJoinedRoom e.g), could you post your code ?

BigGameCo
2020-04-12 00:53:49

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
2020-04-12 08:31:36

Hi @ChuppaFlow,

Thank you for choosing Photon!

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.

Back to top