Greeting everyone,
i was using un 5.2 for quite a while , my game was working and players were able to find session using the null sub system, during develpmenet i was able to test the session connection using the same machine (lan), by running two instances i was able to create host game and join game , from the client i was unable to find the session that was created by the host
im not sure if while upgrading they changed things or not , although i checked the release notes but did not find anything there
this is my code for the create session:
void UMultiplayerSessionsSubsystem::FindSessions(int32 MaxSearchResults)
{
if (!SessionInterface.IsValid())
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("SessionInterface is not valid!"));
return;
}
FindSessionsCompleteDelegateHandle = SessionInterface->AddOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegate);
LastSessionSearch = MakeShareable(new FOnlineSessionSearch());
LastSessionSearch->MaxSearchResults = MaxSearchResults;
LastSessionSearch->bIsLanQuery = IOnlineSubsystem::Get()->GetSubsystemName() == "NULL" ? true : false;
LastSessionSearch->QuerySettings.Set(SEARCH_PRESENCE, true, EOnlineComparisonOp::Equals);
const ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController();
if (!SessionInterface->FindSessions(*LocalPlayer->GetPreferredUniqueNetId(), LastSessionSearch.ToSharedRef()))
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("FindSessions call failed"));
SessionInterface->ClearOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegateHandle);
MultiplayerOnFindSessionsComplete.Broadcast(TArray<FOnlineSessionSearchResult>(), false);
}
}
void UMultiplayerSessionsSubsystem::CreateSession(int32 NumPublicConnections, FString MatchType, FString ServerName)
{
DesiredNumPublicConnections = NumPublicConnections;
DesiredMatchType = MatchType;
DesiredServerName = ServerName;
if (!SessionInterface.IsValid())
{
return;
}
auto ExistingSession = SessionInterface->GetNamedSession(NAME_GameSession);
//auto ExistingSession = SessionInterface->GetNamedSession(FName(*ServerName));
if (ExistingSession != nullptr)
{
bCreateSessionOnDestroy = true;
LastNumPublicConnections = NumPublicConnections;
LastMatchType = MatchType;
LastServerName = ServerName;
UE_LOG(LogTemp,Warning,TEXT("Trying to destory the session"))
DestroySession();
}
// Store the delegate in a FDelegateHandle so we can later remove it from the delegate list
CreateSessionCompleteDelegateHandle = SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegate);
LastSessionSettings = MakeShareable(new FOnlineSessionSettings());
LastSessionSettings->bIsLANMatch = IOnlineSubsystem::Get()->GetSubsystemName() == "NULL" ? true : false;
UE_LOG(LogTemp, Warning, TEXT("IsLanMatch: %d"), LastSessionSettings->bIsLANMatch);
UE_LOG(LogTemp, Warning, TEXT("NumPublicConnections: %d"), NumPublicConnections);
LastSessionSettings->bAllowInvites = true;
LastSessionSettings->bIsDedicated = false;
LastSessionSettings->NumPublicConnections = NumPublicConnections;
LastSessionSettings->bAllowJoinInProgress = true;
LastSessionSettings->bAllowJoinViaPresence = true;
LastSessionSettings->bShouldAdvertise = true;
LastSessionSettings->bUsesPresence = true;
LastSessionSettings->Set(FName("MatchType"), MatchType, EOnlineDataAdvertisementType::ViaOnlineServiceAndPing);
LastSessionSettings->Set(FName("ServerName"), DesiredServerName, EOnlineDataAdvertisementType::ViaOnlineServiceAndPing);
////LastSessionSettings->Set(SEARCH_PRESENCE, true, EOnlineDataAdvertisementType::ViaOnlineService);
LastSessionSettings->BuildUniqueId = 1;
LastSessionSettings->bUseLobbiesIfAvailable = true;
const ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController();
if (!SessionInterface->CreateSession(*LocalPlayer->GetPreferredUniqueNetId(), NAME_GameSession, *LastSessionSettings))
{
SessionInterface->ClearOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegateHandle);
// Broadcast our own custom delegate
MultiplayerOnCreateSessionComplete.Broadcast(false);
}
}