From dd23ed77dda3a5e81accc619de8d5d4c0f1958ba Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Fri, 9 Apr 2021 11:47:14 +0100 Subject: [PATCH] Check for UStevesGameViewportClientBase on first input change rather than at Initialize, the latter is too early --- .../Private/StevesGameSubsystem.cpp | 20 ++++++++++++------- .../Public/StevesGameSubsystem.h | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Source/StevesUEHelpers/Private/StevesGameSubsystem.cpp b/Source/StevesUEHelpers/Private/StevesGameSubsystem.cpp index de6b0a4..674a431 100644 --- a/Source/StevesUEHelpers/Private/StevesGameSubsystem.cpp +++ b/Source/StevesUEHelpers/Private/StevesGameSubsystem.cpp @@ -15,13 +15,7 @@ void UStevesGameSubsystem::Initialize(FSubsystemCollectionBase& Collection) { Super::Initialize(Collection); CreateInputDetector(); - InitTheme(); - - auto GI = GetGameInstance(); - auto VC = Cast(GI->GetGameViewportClient()); - if (!VC) - UE_LOG(LogStevesUEHelpers, Warning, TEXT("Your GameViewportClient needs to be set to a subclass of UStevesGameViewportClientBase if you want full functionality!")) - + InitTheme(); } void UStevesGameSubsystem::Deinitialize() @@ -59,6 +53,18 @@ void UStevesGameSubsystem::InitTheme() void UStevesGameSubsystem::OnInputDetectorModeChanged(int PlayerIndex, EInputMode NewMode) { + // We can't check this during Initialize because it's too early + if (!bCheckedViewportClient) + { + auto GI = GetGameInstance(); + auto VC = Cast(GI->GetGameViewportClient()); + if (!VC) + UE_LOG(LogStevesUEHelpers, Warning, TEXT("Your GameViewportClient needs to be set to a subclass of UStevesGameViewportClientBase if you want full functionality!")) + + bCheckedViewportClient = true; + + } + auto GI = GetGameInstance(); auto VC = GI->GetGameViewportClient(); auto SVC = Cast(VC); diff --git a/Source/StevesUEHelpers/Public/StevesGameSubsystem.h b/Source/StevesUEHelpers/Public/StevesGameSubsystem.h index 445fbb8..4cdb8e7 100644 --- a/Source/StevesUEHelpers/Public/StevesGameSubsystem.h +++ b/Source/StevesUEHelpers/Public/StevesGameSubsystem.h @@ -94,6 +94,7 @@ protected: protected: TSharedPtr InputDetector; FFocusSystem FocusSystem; + bool bCheckedViewportClient = false; UPROPERTY(BlueprintReadWrite) UUiTheme* DefaultUiTheme;