question

Amitai Mazliah avatar image
Amitai Mazliah asked

GetMatchmakingTicket not responding

Hi all

I'm trying out the matchmaking using unity SDK

my flow is as follows

private async Task DoQueueAsync()
        {
            var request = new CreateMatchmakingTicketRequest
            {
                Creator = new MatchmakingPlayer
                {
                    Entity = new EntityKey
                    {
                        Id = LoginPlayfab.LoginResult.EntityToken.Entity.Id,
                        Type = LoginPlayfab.LoginResult.EntityToken.Entity.Type
                    }
                },
                GiveUpAfterSeconds = 10,
                QueueName = "myqueue"
            };


            var response = await PlayFabExtension.Run<CreateMatchmakingTicketRequest, CreateMatchmakingTicketResult>(
                (r, o, e, c, h) => PlayFabMultiplayerAPI.CreateMatchmakingTicket(r, o, e),
                request);



            StartCoroutine(CheckMatched(response.TicketId));
        }

private IEnumerator CheckMatched(string ticketId)
        {
            int count = 0;


            while (PreformCheckMatchedAsync(ticketId).Result == false || count < 5)
            {
                count++;
                yield return new WaitForSeconds(6);
            }
        }

private async Task<bool> PreformCheckMatchedAsync(string ticketId)
        {
            var request = new GetMatchmakingTicketRequest
            {
                TicketId = ticketId,
                QueueName = "myqueue",
                EscapeObject = true
            };


            var response = await PlayFabExtension.Run<GetMatchmakingTicketRequest, GetMatchmakingTicketResult>(
                (r, o, e, c, h) => PlayFabMultiplayerAPI.GetMatchmakingTicket(r, o, e),
                request);


            return response.Status == "Matched";
        }

CreateMatchmakingTicketRequest call works and return a response.

but when I reach the GetMatchmakingTicketRequest the app gets stuck and I don't get any response nor timeout

what am I doing wrong?

thanks in advance


Matchmaking
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Amitai Mazliah avatar image
Amitai Mazliah answered

I found the problem and also a solution

apparently you can't combine both async and coronites togethers.

what I did is moved the entire code to async and now it looks like this and works

private async Task DoQueueAsync()
        {
            var request = new CreateMatchmakingTicketRequest
            {
                Creator = new MatchmakingPlayer
                {
                    Entity = new EntityKey
                    {
                        Id = LoginPlayfab.LoginResult.EntityToken.Entity.Id,
                        Type = LoginPlayfab.LoginResult.EntityToken.Entity.Type
                    }
                },
                GiveUpAfterSeconds = 120,
                QueueName = "myqueue"
            };


            var response = await PlayFabExtension.Run<CreateMatchmakingTicketRequest, CreateMatchmakingTicketResult>(
                (r, o, e, c, h) => PlayFabMultiplayerAPI.CreateMatchmakingTicket(r, o, e),
                request);


            var isMatched = await CheckMatchedAsync(response.TicketId);
        }


        private async Task<bool> CheckMatchedAsync(string ticketId)
        {
            int count = 0;
            var matched = false;
            while (!matched && count < 5)
            {
                matched = await PreformCheckMatchedAsync(ticketId);
                count++;
                if (matched)
                    return true;
                else
                    await Task.Delay(6000);
            }


            return matched;
        }


        private async Task<bool> PreformCheckMatchedAsync(string ticketId)
        {
            var request = new GetMatchmakingTicketRequest
            {
                TicketId = ticketId,
                QueueName = "myqueue"
            };


            try
            {
                var response = await PlayFabExtension.Run<GetMatchmakingTicketRequest, GetMatchmakingTicketResult>(
                    (r, o, e, c, h) => PlayFabMultiplayerAPI.GetMatchmakingTicket(r, o, e),
                    request);


                return response.Status == "Matched";
            }
            catch (Exception)
            {
                return false;
            }
        }
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rick Chen avatar image Rick Chen ♦ commented ·

Thank you for sharing the solution. I am glad that you figured it out.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.