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