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

Please check if you can find an answer in our extensive documentation.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

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.

Two Players at same time create two rooms, JoinRandomOrCreateRoom not found in SDK

2021-12-11 07:01:11


I'm using (Real-time) Photon-Javascript_SDK.js (libversion= for COnstruct 2.

Sometimes, when two players try to join a game, it could happen that each will create its own room (instead of joining one room)

To solve this issue as mentioned in the below link:

** Matchmaking Guide | Photon Engine **
Global cross platform multiplayer game backend as a service (SaaS, Cloud) for synchronous and asynchronous games and applications. SDKs are available for android, iOS, .NET., Mac OS, Unity 3D, Windows, Unreal Engine, HTML5 and others.

I need to use JoinRandomOrCreateRoom, but no such function in the whole SDK. Can anyone help, please?


2021-12-13 09:41:41


Please call joinRoom() with 'createIfNotExists' option:

You can find an example of such call in demo-loadbalancing.

2021-12-13 10:52:31


Thanks for your reply.

I tested demo-loadbalancing. But, I need to know the room name (and specified) in the function, which I don't know.

this.joinRoom('rooName', { createIfNotExists: true }, {maxPlayers : 2}); // the issue will not showing here

What I need is to allow (for example) two players to join a game (a room, any room) if not found will create one (with any name), but they both should join the same room. My observation is that sometimes (let say 1 out of 4), the two players if joining at the same time, could be created two different rooms (both waiting).

What I am doing:

1] join a random room

2] If no match is found, create a room (with no name, Photon will create a random name)

// the issue is happening here

What do you think?

2021-12-13 12:18:30

joinRoom() won't help in you case. I misread your question, sorry.

JoinRandomOrCreateRoom is not supported in js sdk. You need to do this in 2 steps, exactly as you described. demo-particle implements such workflow, search for NoRandomMatchFound in app.js

2021-12-13 14:15:27

Thanks Vadim.

It seems it is a well-known issue. The document is outdated, you see:

"Testing Matchmaking Early In Development

If you are testing matchmaking early in development phase and try to join a random room from two clients at about the same time, there is a chance both clients end up on different rooms: this happens because join random room will not return a match for both clients and each one will probably create a new room as none found. So this is expected and OK. To avoid this use JoinRandomOrCreateRoom (seeQuick Match) instead of JoinRandomRoom then CreateRoom. Otherwise, a possible workaround (for development purposes only) would be to add a random delay before (or after) attempting to join a room or retry again. You could also listen for application or lobby statistics to make sure a room at least exists or has been created."

It says "So this is expected and OK", for me it is not expected and it should not be ok. Then it mentioned the solution by using "*JoinRandomOrCreateRoom"*which is not in the SDK anymore.

I ended up doing the workaround as follows:

1] Join a random room

2] If not found, create one

3] Wait for a random delay, if no user joined, then restart the process (from (1))

Note: I found at, they confirmed the issue, and provided the implementation in PUN, is there any equivalent implementation in JS?

2021-12-15 10:02:47

We will look into adding JoinOrCreateRoom as function to JS. It won't happen during the holidays, so .. early next year. We'll try to update this thread when it's out.

2021-12-15 10:41:11

@Tobias Thanks for the update, appreciate your time and efforts.

2022-01-06 16:27:54


We added joinRandomOrCreateRoom() in SDK v4.1.1.2

2022-01-06 22:05:12

Thank you very much for the update.👍️

2022-01-08 11:34:20


I did update SDK (using joinRandomOrCreateRoom) but still the issue happened , in which it is still possible that two players might ended up with spreate rooms (both waiting).

I checked the implementation:

1] Join a rondom room (with CreateIfNotExists = 1)

2] If not found create one.

Which what I was doing before. Am I missing something, or this the best result that I can get?

2022-01-25 13:27:39


Updating the SDK is not enough. You also need to change your code to use new joinRandomOrCreateRoom() method.

2022-01-26 04:04:28


I did, of course. I noticed better results, but it is still happing.

I am almost convinced, it is technically impossible to avoid this issue, it is just the Documentation confused me by saying you can avoid it. Do you believe it should not happen 100% by using 'joinRandomOrCreateRoom'?

Can you try to reproduce the issue from your end, for example, try with a colleague to join a room at the same time multiple times (leave the room without a nameto be generated randomaly)

2022-02-11 16:25:45

JoinRandomOrCreateRoom() should work in 100% of the cases. But there are a few caveats: You can't use the same userID for both clients (so if you store it in the PlayerPrefs, this is tricky), users must be on the same region and game version string (and then a few more).

To recap: You are using the latest JS SDK and you checked the Matchmaking Checklist to avoid known causes for this?

Back to top