question

Peter Wiseman avatar image
Peter Wiseman asked

CreateMatchmakingTicket Unity Example for 1v1 ?

I'm trying to do some basic Matchmaking with the Unity SDK but I can't find an example showing how to do single player matchmaking. I'm just trying to have one player connect to the matchmaking system on one client and then another player on a different client connect and have the two players matched up. The only example code I can find is here:

https://docs.microsoft.com/en-us/gaming/playfab/features/multiplayer/lobby/lobby-matchmaking-sdks/multiplayer-unity-plugin-quickstart

PFEntityKey entityKey = ...; // PlayFab user's entity key
PFEntityKey remoteEntityKey = ...; // another PlayFab user's entity key
string remoteUserAttributesJson = ...; // JSON string with another PlayFab user's attributes for matchmaking


PlayFabMultiplayer.OnMatchmakingTicketStatusChanged += PlayFabMultiplayer_OnMatchmakingTicketStatusChanged;


List<MatchUser> localUsers = new List<MatchUser>();
localUsers.Add(new MatchUser(entityKey, remoteUserAttributesJson));


List<PFEntityKey> membersToMatchWith = new List<PFEntityKey>();
membersToMatchWith.Add(remoteEntityKey);


PlayFabMultiplayer.CreateMatchmakingTicket(
    localUsers,
    "QuickMatchQueueName",
    membersToMatchWith);

The above code seems to request a Matchmaking ticket for a group of players? I don't really understand what the "membersToMatchWith" list is for and I don't think I need it for 1v1, so I've tried the following instead:

// in the result from a successful call to LoginWithCustomID:

PFEntityKey entityKey = new PFEntityKey(result.EntityToken.Entity.Id, result.EntityToken.Entity.Type);


// and then I use this entity key to try to create a match ticket

MatchUser localUser = new MatchUser(entityKey, userAttributesJSON);
PlayFabMultiplayer.CreateMatchmakingTicket(localUser, "TestMatch");

but this gives me the following error in the Unity console:

"no PlayFab entity token was associated with the provided entity key. Use PFMultiplayerSetEntityToken to associate a PlayFab entity token with a PlayFab entity key before passing that entity key to the API"

I'm not sure what to do here because I'm very new to PlayFab and am still trying to get my head around EntityTokens and wotnot. @Brendan could you please point me in the right direction or give me some Unity example code for this? Thanks!

unity3dMatchmaking
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

·
Gosen Gao avatar image
Gosen Gao answered

“membersToMatchWith” should be the other members of the current Lobby, as the SDK you are using is for Lobby and Matchmaking. If you just want to create a Matchmaking ticket for one player, you can refer to Matchmaking quickstart - PlayFab | Microsoft Docs. As for the error, you need to set Entity Token first. You can refer to the code below.

PlayFabMultiplayer.SetEntityToken(LoginResult.AuthenticationContext);
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.

Peter Wiseman avatar image Peter Wiseman commented ·

Well I really needed some Unity example code rather than the REST code that you've linked to as I don't want to keep polling for the result but you mentioned "LoginResult.AuthenticationContext" and that's pushed me in the right direction. Here's my modified code if anyone else wants to do 1v1 with the Unity SDK:

PlayFabAuthenticationContext authenticationContext;

PlayFabMultiplayer.OnMatchmakingTicketStatusChanged += OnMatchmakingTicketStatusChanged;
PlayFabMultiplayer.OnMatchmakingTicketCompleted += OnMatchmakingTicketCompleted;


var request = new LoginWithCustomIDRequest { CustomId = deviceID, CreateAccount = true };

PlayFabClientAPI.LoginWithCustomID(request,
	result => {
		// success
		authenticationContext = result.AuthenticationContext;
	},
	error => {
		// failed
	}
);

string userAttributesJSON = "{\"skillLevel\": \"" + skillLevel + "\"}";
MatchUser localUser = new MatchUser(authenticationContext, userAttributesJSON);
PlayFabMultiplayer.CreateMatchmakingTicket(localUser, "TestMatch");
<br>

I get a callback to OnMatchmakingTicketStatusChanged with a status of "WaitingForMatch" so it looks like it's working. Thanks!

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.