Check for UStevesGameViewportClientBase on first input change rather than at Initialize, the latter is too early

This commit is contained in:
Steve Streeting 2021-04-09 11:47:14 +01:00
parent eead056575
commit dd23ed77dd
2 changed files with 14 additions and 7 deletions

View File

@ -15,13 +15,7 @@ void UStevesGameSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{ {
Super::Initialize(Collection); Super::Initialize(Collection);
CreateInputDetector(); CreateInputDetector();
InitTheme(); InitTheme();
auto GI = GetGameInstance();
auto VC = Cast<UStevesGameViewportClientBase>(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!"))
} }
void UStevesGameSubsystem::Deinitialize() void UStevesGameSubsystem::Deinitialize()
@ -59,6 +53,18 @@ void UStevesGameSubsystem::InitTheme()
void UStevesGameSubsystem::OnInputDetectorModeChanged(int PlayerIndex, EInputMode NewMode) 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<UStevesGameViewportClientBase>(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 GI = GetGameInstance();
auto VC = GI->GetGameViewportClient(); auto VC = GI->GetGameViewportClient();
auto SVC = Cast<UStevesGameViewportClientBase>(VC); auto SVC = Cast<UStevesGameViewportClientBase>(VC);

View File

@ -94,6 +94,7 @@ protected:
protected: protected:
TSharedPtr<FInputModeDetector> InputDetector; TSharedPtr<FInputModeDetector> InputDetector;
FFocusSystem FocusSystem; FFocusSystem FocusSystem;
bool bCheckedViewportClient = false;
UPROPERTY(BlueprintReadWrite) UPROPERTY(BlueprintReadWrite)
UUiTheme* DefaultUiTheme; UUiTheme* DefaultUiTheme;