diff --git a/Game/Source/GDKShooter/Private/Deployments/DeploymentsPlayerController.cpp b/Game/Source/GDKShooter/Private/Deployments/DeploymentsPlayerController.cpp index 91be96b5..b2367f5f 100644 --- a/Game/Source/GDKShooter/Private/Deployments/DeploymentsPlayerController.cpp +++ b/Game/Source/GDKShooter/Private/Deployments/DeploymentsPlayerController.cpp @@ -4,6 +4,7 @@ #include "SpatialGameInstance.h" #include "TimerManager.h" +#include "SpatialGDKSettings.h" #include "SpatialWorkerConnection.h" #include "GDKLogging.h" @@ -18,6 +19,12 @@ void ADeploymentsPlayerController::BeginPlay() USpatialGameInstance* SpatialGameInstance = GetGameInstance(); SpatialWorkerConnection = SpatialGameInstance->GetSpatialWorkerConnection(); + if (SpatialWorkerConnection == nullptr) + { + // We might not be using spatial networking in which case SpatialWorkerConnection will not exist so we should just return + return; + } + FString SpatialWorkerType = SpatialGameInstance->GetSpatialWorkerType().ToString(); SpatialWorkerConnection->RegisterOnLoginTokensCallback([this](const Worker_Alpha_LoginTokensResponse* Deployments){ Populate(Deployments); @@ -28,7 +35,10 @@ void ADeploymentsPlayerController::BeginPlay() return true; }); - SpatialWorkerConnection->Connect(true, 0); + if (GetDefault()->bUseDevelopmentAuthenticationFlow) + { + SpatialWorkerConnection->Connect(true, 0); + } } void ADeploymentsPlayerController::EndPlay(const EEndPlayReason::Type Reason) diff --git a/Game/Source/GDKShooter/Private/UI/GDKWidget.cpp b/Game/Source/GDKShooter/Private/UI/GDKWidget.cpp index ee279e09..4d493077 100644 --- a/Game/Source/GDKShooter/Private/UI/GDKWidget.cpp +++ b/Game/Source/GDKShooter/Private/UI/GDKWidget.cpp @@ -4,6 +4,7 @@ #include "Components/ControllerEventsComponent.h" #include "Components/GDKMovementComponent.h" #include "Components/HealthComponent.h" +#include "EngineClasses/SpatialGameInstance.h" #include "Game/Components/LobbyTimerComponent.h" #include "Game/Components/MatchTimerComponent.h" #include "Game/Components/PlayerCountingComponent.h" @@ -106,6 +107,11 @@ void UGDKWidget::LeaveGame(const FString& TargetMap) FURL TravelURL; TravelURL.Map = *TargetMap; + if (USpatialGameInstance* GameInstance = Cast(GetGameInstance())) + { + GameInstance->GetSpatialWorkerConnection()->DestroyConnection(); + } + GetOwningPlayer()->ClientTravel(TravelURL.ToString(), TRAVEL_Absolute, false /*bSeamless*/); }