immersionfields avatar image
immersionfields asked

Dedicated Server Matchmaking using OnlineSubsystemPlayfab

Hello, I couldn't find online any information about the implementation of matchmaking using OnlineSubsystemPlayfab, I promise to open-source my code if you can help me out so that others can have a smoother experience in the future. I do know how to do it with findsession and joinsession, but as far as I understand it won't open the dedicated server, and the way to do it using the cloud system is with startmatchmaking

This is what I currently did

 #include "MatchmakingManager.h"
 #include "OnlineSubsystemPlayFab.h"
 #include "Interfaces/OnlineSessionInterface.h"
 #include "OnlineSessionSettings.h"
 void AMatchmakingManager::BeginPlay()
     IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get();
     IOnlineSessionPtr session = OnlineSubsystem->GetSessionInterface();
     IOnlineIdentityPtr IdentityInterface = OnlineSubsystem->GetIdentityInterface();
     FOnlineSessionSettings SessionSettings;
     SessionSettings.bAllowInvites = true;
     SessionSettings.bAllowJoinInProgress = true;
     SessionSettings.bAllowJoinViaPresence = true;
     SessionSettings.bAllowJoinViaPresenceFriendsOnly = false;
     SessionSettings.bAntiCheatProtected = false;
     SessionSettings.bIsDedicated = true;
     SessionSettings.bIsLANMatch = false;
     SessionSettings.bShouldAdvertise = true;
     SessionSettings.bUseLobbiesIfAvailable = true;
     SessionSettings.bUseLobbiesVoiceChatIfAvailable = true;
     SessionSettings.bUsesPresence = true;
     SessionSettings.bUsesStats = true;
     TSharedRef<FOnlineSessionSearch> SessionSearch = MakeShareable(new FOnlineSessionSearch());
     SessionSearch.Get().bIsLanQuery = false;
     SessionSearch.Get().MaxSearchResults = 1;
     FOnStartMatchmakingComplete StartMatchmakingCompleteDelegate;
     StartMatchmakingCompleteDelegate.BindUObject(this, &AMatchmakingManager::OnStartMatchmakingComplete);
     TArray<FSessionMatchmakingUser> LocalPlayers;
     FSessionMatchmakingUser MatchmakingUser;
     MatchmakingUser.UserId = IdentityInterface->GetUniquePlayerId(0).ToSharedRef();
     session->StartMatchmaking(LocalPlayers, FName("Playtest"), SessionSettings, SessionSearch, StartMatchmakingCompleteDelegate);

Here's the function that it will call once complete:

 void AMatchmakingManager::OnStartMatchmakingComplete(FName SessionName, const FOnlineError& ErrorDetails, const FSessionMatchmakingResults& Results)
     // on matchmaking complete logic

I noticed that FSessionMatchmakingResults is a "Stub struct that can be easily added to without requiring delegate signature changes". Am I expected to populate it with properties so that I can get information from the results? How do I even make sure that playfab is using the right build?

Would love to hear how to continue from there.

By the way, I did create a working matchmaking with the default Playfab package, but it does not support voice-chat by default as OnlineSubsystemPlayfab does

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

mavapf avatar image
mavapf answered

It seems that after you begin cloud based matchmaking for a session via IOnlineSession::StartMatchmaking | Unreal Engine Documentation, you should handle the FOnlineSessionSearch which contains SearchResults in OnMatchmakingCompleteDelegates, and the SearchResults contains session information, then you can use it and SessionName to Join the specified session by IOnlineSession::JoinSession.

10 |1200

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

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.