Invalid Match Id (Empty string)

I’m using Nakama C++ with Unreal Engine.

I’ve got it working up to Authentication, joining pools, and authentication. However when I try to join the match I get an “Invalid match id” error.

If I debug I notice that the matchId is an empty string. The debug printout:

matchId = ""
    ticket = "6debf08e-af61-4826-8271-c902eda8579e"
    token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NjI2NDI1MjIsIm1pZCI6IjRmMTg3ODM0LTBkNmMtNDU0OC05OTE1LTcyZmI1MzAyOTU0Ni4ifQ.HDEZbHaHcMmimRaoO2rN2bkhG25fimNQEJuT4sGSD6g"

Here is the code:

void UNetworkManager::FindMatch() {
	int32_t minPlayers = 2;
	int32_t maxPlayers = 2;
	std::string query = "*";

	auto onJoinedPool = [](const NMatchmakerTicket& ticket) {
		UE_LOG(LogTemp, Warning, TEXT("Nakama: Joined Pool"));

	RTNetworkClient->addMatchmaker(minPlayers, maxPlayers, query, {}, {}, onJoinedPool);

	NetworkListener.setMatchmakerMatchedCallback([this](NMatchmakerMatchedPtr matched)
		UE_LOG(LogTemp, Warning, TEXT("Nakama: Match Found"));

void UNetworkManager::JoinMatch(string matchId)
	RTNetworkClient->joinMatch(matchId, [this](const NMatch& match)
			UE_LOG(LogTemp, Warning, TEXT("Nakama: Joining Match"));
			std::vector<FNetworkUser> users(match.presences.size());
			std::transform(match.presences.begin(), match.presences.end(), users.begin(), [](NUserPresence user) {
				return FNetworkUser { user.username.c_str(), user.userId.c_str() };

			if (users.size() > 0)
				TArray<FNetworkUser> usersTArr;
				usersTArr.Append(&users[0], users.size());

				FNetworkUser currentUser{ match.self.username.c_str(), match.self.userId.c_str() };
				OnMatchFound(FMatchInfo{ match.matchId.c_str(), currentUser, usersTArr });

If it helps, what I’m trying to do is match any two players in a 1v1 realtime game. I thought matchmaking could do this for me without having to have a client call createMatch

Hi @spentak. You’re on track and all the code you’ve shown looks good.

The difference with the matchmaker and relayed matches created by client-side code is that the matchmaker will give you a token that you use to join the match with. This token is used by the game server to create the match if no other peers are connected to it at the time of the initial join by the current player.

This design choice is because the matchmaker does not create a match on the server (i.e. a multiplayer stream if it’s a relayed match) but instead gives the player a way to join which can be validated by the server. (The token is actually a JWT with a signing key.)

You can see more docs on it here.

Hope this helps.

From code you posted I don’t see how JoinMatch is implemented.
You should use joinMatchByToken method.

1 Like

Okay joinMatchByToken is what I needed. Thanks for the help!

Honestly, I went through every page of gameplay docs and didn’t see this anywhere. One of the really hard things coming into Nakama brand new is understanding the flow.

I think it would be super helpful to have some small example projects. The code snippets have no context. Or maybe even just some flow diagrams.

SampleProject: Creating and joining a realtime multiplayer game
SampleProject: Creating and joining a turn based multiplayer game

Glad you solved the issue.
Yes, will update docs :+1:

SampleProject: Creating and joining a realtime multiplayer game
SampleProject: Creating and joining a turn based multiplayer game

This is a great suggestion. We do have a full example project for Unity Engine which shows a realtime multiplayer game:

This won’t be directly useful because it’s not a C++ project but does show a contextual example on how to use pretty much all of the APIs in the game server.