我正在写一个局域网联机的Demo,我使用CreateSession来创建一个Session并传入我需要的SessionSettings,但是当我从另一台计算机查找Session时,另一台设备确实找到了一个Session,但是其中的数据完全没有初始化,我的代码如下。
FOnlineSessionSettings SessionSettings = FOnlineSessionSettings();
if(!Params.bUseLAN)
{
SessionSettings.bIsLANMatch = IOnlineSubsystem::Get()->GetSubsystemName() == "NULL" ? true : false;
}
else
{
SessionSettings.bIsLANMatch = true;
}
SessionSettings.NumPublicConnections = Params.NumPublicConnections;
SessionSettings.bAllowJoinInProgress = true;
SessionSettings.bAllowJoinViaPresence = true;
SessionSettings.bShouldAdvertise = true;
SessionSettings.bUsesPresence = true;
SessionSettings.Settings = Params.Settings;
SessionSettings.BuildUniqueId = 1;
SessionSettings.bUseLobbiesIfAvailable = true;
const ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController();
if (!OnlineSessionInterface->CreateSession(*LocalPlayer->GetPreferredUniqueNetId(), NAME_GameSession, SessionSettings))
{
MultiplayerOnCreateSessionComplete.Broadcast(false);
OnlineSessionInterface->ClearOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegateHandle);
}
//下面是查找Session的部分
sessionSearch = MakeShareable(new FOnlineSessionSearch);
sessionSearch->MaxSearchResults = MaxSearchResults;
if(Params.bUseLAN)
{
sessionSearch->bIsLanQuery = true;
}
else
{
sessionSearch->bIsLanQuery = IOnlineSubsystem::Get()->GetSubsystemName() == "NULL" ? true : false;
}
sessionSearch->QuerySettings = Params.Settings;
sessionSearch->QuerySettings.Set(SEARCH_PRESENCE, true, EOnlineComparisonOp::Equals);
const ULocalPlayer* localPlayer = GetWorld()->GetFirstLocalPlayerFromController();
if (!OnlineSessionInterface->FindSessions(*localPlayer->GetPreferredUniqueNetId(), sessionSearch.ToSharedRef()))
{
MultiplayerOnFindSessionsComplete.Broadcast(TArray<FOnlineSessionSearchResult>{}, false);
OnlineSessionInterface->ClearOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegateHandle);
MultiplayerLog.Broadcast(TEXT("Find sessions failed with unknown error!"));
}
我感到非常困惑,我想知道这是什么原因导致的