I’ve been trying to get the values from the Online Session Search Result to my Row Widget (named Server Entry). However, everytime it tries to read the FServerData values, it crashes.
Code in GI where Server Data is set and passed to the menu widget:
void UMyGameInstance::OnFindServersComplete(bool Success)
{
UE_LOG(LogTemp, Error, TEXT("Browsing Complete"));
if (!Success || !SearchSettingsPtr.IsValid() || !JoinGameMenu)
{
UE_LOG(LogTemp, Error, TEXT("Browsing not successful, or Search Settings no longer valid"));
return;
}
//Iterator for Index referencing purposes
int32 Itr = 0;
//Register each Server Entry to the Server Browser Widget
for (FOnlineSessionSearchResult& SearchResult : SearchSettingsPtr->SearchResults)
{
if (SearchResult.IsValid())
{
FServerData ServerData;
ServerData.Name = SearchResult.GetSessionIdStr();
ServerData.MaxPlayers = SearchResult.Session.SessionSettings.NumPublicConnections;
ServerData.CurrentPlayers = ServerData.MaxPlayers - SearchResult.Session.NumOpenPublicConnections;
ServerData.Ping = SearchResult.PingInMs;
ServerData.SearchIndex = Itr;
UE_LOG(LogTemp, Error, TEXT("Attempting to Register Server Entry: %s - %d - %d"), *SearchResult.GetSessionIdStr(), SearchResult.PingInMs, SearchResult.Session.SessionSettings.NumPublicConnections);
JoinGameMenu->RegisterServerEntry(ServerData);
Itr++;
}
}
}
And, where the functionality is in my menu widget:
void UWULJoinSubMenu::RegisterServerEntry(FServerData& ServerData)
{
//Create Widget for Server Entry
UWULServerEntry* NewEntry = CreateWidget<UWULServerEntry>(this, UWULServerEntry::StaticClass());
if (NewEntry)
{
//Null-Check Search Results
if (MyGameInstance->SearchSettingsPtr.IsValid())
{
if (ServerData.Name.IsEmpty())
{
UE_LOG(LogTemp, Error, TEXT("Server not named"));
}
else
{
//Set values for
NewEntry->PlayerCountText->SetText(FText::FromString(FString::FromInt(ServerData.CurrentPlayers) + "/" + FString::FromInt(ServerData.MaxPlayers)));
NewEntry->PingText->SetText(FText::FromString(FString::FromInt(ServerData.Ping)));
NewEntry->ServerNameText->SetText(FText::FromString(ServerData.Name));
ServerList->AddChild(NewEntry);
}
}
else UE_LOG(LogTemp, Error, TEXT("Invalid Search Settings or Search Result"));
}
}
I’ve deviated from the lecture code a bit, but I believe I’ve kept the concept the same. I know that the Search Result is valid, because in my log it writes: [2022.06.14-01.02.35:968][906]LogTemp: Error: Attempting to Register Server Entry: FE2DF01F4C7A53E2873B8586D4459702 - 118 - 10
. However, once I try to call the values in the struct and pass them to the Set Text function in my widget, I get a nullptr error.
Has anyone encountered this or would be able to tell me what’s happening?
I appreciate the help!