Hello, I have been trying to fix an issue with our student game for a whole year now. Our entire multiplayer system works very well and can be used on Steam or Epic Games with the CrossPlatform system.
However, since the beginning of the project, we have been unable to search for sessions.
Using the FindSession and FindSessionAdvanced nodes from AdvancedSessions does not work at all and always returns 0.
Also in C++.
However, on the Epic DevPortal, we can clearly see the sessions displayed with the session settings and players, and we can play the game using the Steam and Epic Game invitation system to join a game.
But, searching for a session does not work.
LogTemp: Display: Finding sessions…
LogEOSSDK: Verbose: LogEOSAnalytics: Record Event: EOSSDK.HTTP.Complete <Redacted>
Are you saying you’ve tried it with both that code and the blueprint node? Looking at the log file and additional excerpt you provided above, I don’t see the log output from the CPP code that I would expect. Would you be able to show the logging from that code?
#include "MyGameInstance.h"
#include "OnlineSubsystem.h"
#include "OnlineSessionSettings.h"
UMyGameInstance::UMyGameInstance()
{
}
void UMyGameInstance::FindSessions()
{
// 1. Get the Online Subsystem
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get();
if (Subsystem)
{
// 2. Get the Session Interface
IOnlineSessionPtr SessionInterface = Subsystem->GetSessionInterface();
if (SessionInterface.IsValid())
{
// 3. Create the Search Object
SessionSearch = MakeShareable(new FOnlineSessionSearch());
// 4. Configure Search Settings
// If using NULL subsystem (Testing), set this to true. For Steam/EOS, set to false.
SessionSearch->bIsLanQuery = false;
// Search for Presence sessions (Lobby sessions generally require this)
SessionSearch->QuerySettings.Set(SEARCH_PRESENCE, true, EOnlineComparisonOp::Equals);
// Set max results to avoid fetching too many
SessionSearch->MaxSearchResults = 100;
// 5. Bind the Delegate
// We register the function to run when the search is done
FindSessionsCompleteDelegateHandle = SessionInterface->AddOnFindSessionsCompleteDelegate_Handle(
FOnFindSessionsCompleteDelegate::CreateUObject(this, &UMyGameInstance::OnFindSessionsComplete)
);
// 6. Execute the Search
UE_LOG(LogTemp, Log, TEXT("Starting Session Search..."));
SessionInterface->FindSessions(0, SessionSearch.ToSharedRef());
}
}
}
void UMyGameInstance::OnFindSessionsComplete(bool bWasSuccessful)
{
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get();
if (Subsystem)
{
IOnlineSessionPtr SessionInterface = Subsystem->GetSessionInterface();
if (SessionInterface.IsValid())
{
// Always clear the delegate handle to prevent memory leaks or crashes
SessionInterface->ClearOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegateHandle);
}
}
if (bWasSuccessful && SessionSearch.IsValid())
{
UE_LOG(LogTemp, Log, TEXT("Session Search Completed. Found %d sessions."), SessionSearch->SearchResults.Num());
// Loop through results
for (const FOnlineSessionSearchResult& SearchResult : SessionSearch->SearchResults)
{
// Print Session ID and User Name
UE_LOG(LogTemp, Log, TEXT("Found Session Name: %s"), *SearchResult.Session.OwningUserName);
// Example: Join the first valid session found
// SessionInterface->JoinSession(0, NAME_GameSession, SearchResult);
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Session Search Failed."));
}
}