I’ve implemented one of the suggested fixes for the crash that would happen when the server leaves to return to the main menu while clients are attached. When the “server” leaves the game to go back to the main menu, I was able to get all the attached clients to return to their main menu instances as well. The problem I am having is that when the Network Error is thrown and logged, the delegate runs the attached function, but the “clients” get stuck in what I think is an infinite log of the following errors…
This sequence of errors continue to log (or at least continue to log until I got tired of waiting for the end). I believe the delegate then continues to run the attached function repeatedly. Again, I think that this is what causes the widget from being interacted with and the user cannot execute the “host”, “join”, or “Exit” buttons. Everything else in project has worked great, I was just hoping to work out this final bug.
So I’ve been trying a few different things here and there to try and get this issue fixed, but I’ve found myself stuck. Any suggestions would be great. My game instance.cpp code is below for reference.
void UPuzzlePlatformsGameInstance::Init()
{
UE_LOG(LogTemp, Warning, TEXT("Found class %s"), *MenuClass->GetName());
UEngine* Engine = GetEngine();
if (!ensure(Engine != nullptr)) return;
Engine->OnNetworkFailure().AddUObject(this, &UPuzzlePlatformsGameInstance::ServerEndsSession);
}
void UPuzzlePlatformsGameInstance::LoadMenu()
{
if (!ensure(MenuClass != nullptr)) return;
Menu = CreateWidget<UMainMenu>(this, MenuClass);
Menu->Setup();
Menu->SetMenuInterface(this);
}
void UPuzzlePlatformsGameInstance::InGameLoadMenu()
{
if (!ensure(InGameMenuClass != nullptr)) return;
InGameMenu = CreateWidget<UMenuWidget>(this, InGameMenuClass);
InGameMenu->Setup();
InGameMenu->SetMenuInterface(this);
}
void UPuzzlePlatformsGameInstance::Host()
{
if (Menu != nullptr)
{
Menu->OnLevelRemovedFromWorld(GetWorld()->GetLevel(0), GetWorld());
}
UEngine* Engine = GetEngine();
if (!ensure(Engine != nullptr)) return;
Engine->AddOnScreenDebugMessage(0, 2, FColor::Green, TEXT("Hosting"));
UWorld* World = GetWorld();
if (!ensure(World != nullptr)) return;
World->ServerTravel("/Game/ThirdPersonCPP/Maps/ThirdPersonExampleMap?listen");
}
void UPuzzlePlatformsGameInstance::Join(const FString& Address)
{
if (Menu != nullptr)
{
Menu->OnLevelRemovedFromWorld(GetWorld()->GetLevel(0), GetWorld());
}
UEngine* Engine = GetEngine();
if (!ensure(Engine != nullptr)) return;
Engine->AddOnScreenDebugMessage(0, 5, FColor::Green, FString::Printf(TEXT("Joining %s"), *Address));
APlayerController* PlayerController = GetFirstLocalPlayerController();
if (!ensure(PlayerController != nullptr)) return;
PlayerController->ClientTravel(Address, ETravelType::TRAVEL_Absolute);
}
void UPuzzlePlatformsGameInstance::ReturnToMainMenu()
{
APlayerController* PlayerController = GetFirstLocalPlayerController();
if (!ensure(PlayerController != nullptr)) return;
PlayerController->ClientTravel("/Game/MenuSystem/MainMenu", ETravelType::TRAVEL_Absolute);
}
void UPuzzlePlatformsGameInstance::ServerEndsSession(UWorld* World, UNetDriver* NetDriver, ENetworkFailure::Type FailureType, const FString& ErrorString)
{
LoadMenu();
}```