Find Sessions not working on C++ with Steam

Hi, I got a simple matchmaking game that I’m migrating from blueprints to C++, but now I’m stuck at this point:
I cannot find any session from C++, I create the session from C++ then, I try to find games, on blueprints is working well but not on C++, why?

Here is the code (not working):

void UNetGameInstance::FindSessions(TSharedPtr<const FUniqueNetId> UserId, FName SessionName, bool bIsLAN, bool bIsPresence) {
	IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
	if (OnlineSub) {
		IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
		if (Sessions.IsValid() && UserId.IsValid()) {
			SessionSearch = MakeShareable(new FOnlineSessionSearch());
			SessionSearch->bIsLanQuery = bIsLAN;
			SessionSearch->MaxSearchResults = 20;
			SessionSearch->PingBucketSize = 50;

			if (bIsPresence) {
				SessionSearch->QuerySettings.Set(SEARCH_PRESENCE, bIsPresence, EOnlineComparisonOp::Equals);
			}

			const TSharedRef< FOnlineSessionSearch > SearchSettingsRef = SessionSearch.ToSharedRef();

			OnFindSessionsCompleteDelegateHandle = Sessions->AddOnFindSessionsCompleteDelegate_Handle(OnFindSessionsCompleteDelegate);

			Sessions->FindSessions(*UserId, SearchSettingsRef);
			
		}
	} else {
		OnFindSessionsComplete(false);
	}
}

void UNetGameInstance::OnFindSessionsComplete(bool bWasSuccessful) {
	IOnlineSubsystem* const OnlineSub = IOnlineSubsystem::Get();
	if (OnlineSub) {
		IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
		if (Sessions.IsValid()) {
			Sessions->ClearOnFindSessionsCompleteDelegate_Handle(OnFindSessionsCompleteDelegateHandle);
			GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::White, FString::Printf(TEXT("Num Search Results: %d"), SessionSearch->SearchResults.Num()));
			if (SessionSearch->SearchResults.Num() > 0) {
				for (int32 SearchIdx = 0; SearchIdx < SessionSearch->SearchResults.Num(); SearchIdx++) {
					GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::White, FString::Printf(TEXT("Session Number: %d | Sessionname: %s "), SearchIdx + 1, *(SessionSearch->SearchResults[SearchIdx].Session.OwningUserName)));
				}
			}
		}
	}
}

And here is the blueprint (working)

I’m missing something?
Thx :slight_smile:

You aren’t checking whether it was successful or not. Secondly, double check that bIsLan is not true, since your Blueprint which works is not using that.

I add the check of bWasSuccessful and checked that bIsLan is false and still 0 results from C++ :frowning:

By the way, this C++ code is finding properly the sessions without steam, but isn’t able to find any steam session

In that case, you must have some mismatch between what the host is registering and what the client is searching for. Dump all of the settings and make sure they match.

What values are you calling FindSessions in c++ with?

The default FindSessionsAsyncCallback class (the blueprint version) uses bIsPresence true, make sure that is also set true in your C++ call.

For UE4’s default Steam OnlineSubsystem, the Presence flag is used to control whether you are doing a Lobby search or if you’re using the older dedicated server system (not to imply that this is what it SHOULD be used for…)

Presence doesn’t matter for searching. Presence just means that session is used for the rich presence string for the player, e.g. “Playing Execution on Gridlock”