asadm / playroom-unity

9 stars 1 forks source link

StartMatchmaking does not work when matchmaking=false #58

Closed SaadBazaz closed 1 month ago

SaadBazaz commented 2 months ago

What happened?

In Unity, if I call InsertCoin with matchmaking == true, if seems to work fine. But I call InsertCoin with matchmaking == false, then call StartMatchmaking after that, I get an error.

Here is my code:

private IEnumerator StartMatchmakingCoroutine()
{
    NetworkManager.Instance.Initialize();       //  Call InsertCoin with matchmaking = false

    yield return new WaitUntil(() => NetworkManager.Instance.GetPlayers().Count > 0);

    NetworkManager.Instance.StartMatchmaking(); //  Call StartMatchmaking
}

\

Version

0.0.14

What is your environment?

Unknown

Link to original discussion

https://discord.com/channels/997752993598419044/1228773906710528144

Relevant log output

In the console log image:

  1. the first line is printed after InsertCoin, in the OnPlayerJoin callback.
  2. the second line is printed after StartMatchmaking, in the OnQuit callback
  3. the third line (error line) is printed just after that

image

After that, I get even more errors:

image

SaadBazaz commented 2 months ago

Current recommendation

Instead of setting matchmaking = false, leave it null or undefined.

For example, instead of:

PlayroomKit.insertCoin(
  matchmaking=false, 
  //... other options
)

You could try:

PlayroomKit.insertCoin(
  //... other options, no matchmaking option at all
)

Next steps

Will close the Issue if the above recommendations yield positive results, or if the Issue become stale.

Update 25/04/24:

SaadBazaz commented 2 months ago

Reproduction

Paraphrasing @momintlh:

I have tested the StartMatchMaking one, it first works fine then if a player leaves the game will crash and the attached ID error is thrown. after that I get the other abnormal behavior error, that is due to the coroutine, provided in the example. image

Not setting matchmaking within insertcoin's initoption leads to the same result because its default value is false. It cannot be null because it's a C# bool.

Marking this as an issue which needs to be solved.

momintlh commented 2 months ago

Going to test without using GetPlayers(), I will maintain a list on the games side and use that.

SaadBazaz commented 2 months ago

Going to test without using GetPlayers(), I will maintain a list on the games side and use that.

That sounds like a good idea to narrow it down. Did it work?

momintlh commented 2 months ago

Going to test without using GetPlayers(), I will maintain a list on the games side and use that.

That sounds like a good idea to narrow it down. Did it work?

Getting the same error

SaadBazaz commented 1 month ago

If you can share an alt snippet which people can use instead of using it incorrectly, that could work as a solution too.

momintlh commented 1 month ago

The code below achieves the same goal and leads to the same error

private void Initialize()
    {
        PlayroomKit.InsertCoin(new PlayroomKit.InitOptions()
        {
            maxPlayersPerRoom = 2,
            roomCode = "abc",
            matchmaking = false,
            defaultPlayerStates = new() {
                        {"score", 0},
                    },

        }, () =>
        {
            PlayroomKit.OnPlayerJoin(AddPlayer);
            PlayroomKit.StartMatchmaking();
        });
    }

From my understanding the error is occurring when the room changes.

momintlh commented 1 month ago

The fix might be this: Wait for the room change, (maybe by reading the URL) and only then call MyPlayer / or Update. I'll try this and report.

SaadBazaz commented 1 month ago

Resolved in #70