Enhanced Input not working with CommonUI

My game is a VN-style game so it is mostly UMG widgets (CommonUI).
When said widgets are on screen, my IAs no longer work.
I can see the context is loaded in the Enhanced Input debug, but nothing happens when I press a key.
Any ideas on what to try would be appreciated!!!

I think you should update the input mode

UWidgetBlueprintLibrary::SetInputMode_GameAndUI();
UWidgetBlueprintLibrary::SetInputMode_GameOnly();
UWidgetBlueprintLibrary::SetInputMode_UIOnly();

I’ve tried every input mode.
GameOnly works until I click the widget.
I’m guessing CommonUI is setting it to a mode that blocks input?

try this:

APlayerController::APlayerController(const FObjectInitializer& ObjectInitializer): Super(ObjectInitializer)

{
PrimaryActorTick.bCanEverTick = true;
bEnableMotionControls = true;
AutoReceiveInput = EAutoReceiveInput::Type::Disabled;
InputPriority = 0;
bBlockInput = false;
bNetLoadOnClient = true;
}

and

SetFocusable(false); //in your widget bluprint

No difference sadly…
After reading this.
I might have to stop using “CommonActivatbleWidget”

I had the same problem two weeks ago.
I managed to solve it.
But don’t post the solution.

I’ve been looking for a while in my code to see what the hell I did but I can’t remember.

What I do know is that I was right… it was a conflict between the focus and the input mode.

If I find the solution I will come back


i found this:

void APlayerController::BeginPlay()
{
Super::BeginPlay();
if(InputComponent!=nullptr)
{
const FInputModeDataBase &InData = FInputModeGameAndUI();
SetInputMode(InData);

}
}

AHUD::AHUD(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
PrimaryActorTick.bStartWithTickEnabled = false;
//SetFocusable();
InputPriority = 0;
bShowOverlays = true;
}

void ACGamePlayPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
//EnablePawnInput();
bEnableMotionControls = true;
OverridePlayerInputClass = UEnhancedInputComponent::StaticClass();
AutoReceiveInput = EAutoReceiveInput::Type::Disabled;
InputPriority = 0;
bBlockInput = false;
EnableInput(this);
SetShowMouseCursor(false);
UWidgetBlueprintLibrary::SetInputMode_GameOnly(this, false);

}

void ACGamePlayPlayerController::BeginPlay()
{
Super::BeginPlay();
SetShowMouseCursor(false);
}

void ACGamePlayPlayerController::DisablePawnInput()
{
const APawn* MyPawn = GetPawn();
if (MyPawn == nullptr)
{
return;
}
if (MyPawn->IsLocallyControlled())
{
DisableInput(this);
}
}

void ACGamePlayPlayerController::EnablePawnInput()
{
const APawn* MyPawn = GetPawn();
if (MyPawn == nullptr)
{
return;
}
if (MyPawn->IsLocallyControlled())
{
EnableInput(this);
return;
}
}

I hope you can solve the problem

The problem here is “CommonActivatableWidget”.
It sets the game input mode on activation.

Extending the class as they did in Lyra is a workaround for this.
h file:

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CommonActivatableWidget.h"

#include "LyraActivatableWidget.generated.h"

struct FUIInputConfig;

UENUM(BlueprintType)
enum class ELyraWidgetInputMode : uint8
{
	Default,
	GameAndMenu,
	Game,
	Menu
};

// An activatable widget that automatically drives the desired input config when activated
UCLASS(Abstract, Blueprintable)
class ULyraActivatableWidget : public UCommonActivatableWidget
{
	GENERATED_BODY()

public:
	ULyraActivatableWidget(const FObjectInitializer& ObjectInitializer);
	
public:
	
	//~UCommonActivatableWidget interface
	virtual TOptional<FUIInputConfig> GetDesiredInputConfig() const override;
	//~End of UCommonActivatableWidget interface

#if WITH_EDITOR
	virtual void ValidateCompiledWidgetTree(const UWidgetTree& BlueprintWidgetTree, class IWidgetCompilerLog& CompileLog) const override;
#endif
	
protected:
	/** The desired input mode to use while this UI is activated, for example do you want key presses to still reach the game/player controller? */
	UPROPERTY(EditDefaultsOnly, Category = Input)
	ELyraWidgetInputMode InputConfig = ELyraWidgetInputMode::Default;

	/** The desired mouse behavior when the game gets input. */
	UPROPERTY(EditDefaultsOnly, Category = Input)
	EMouseCaptureMode GameMouseCaptureMode = EMouseCaptureMode::CapturePermanently;
};

cpp file:

// Copyright Epic Games, Inc. All Rights Reserved.

#include "LyraActivatableWidget.h"

#include "Editor/WidgetCompilerLog.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraActivatableWidget)

#define LOCTEXT_NAMESPACE "Lyra"

ULyraActivatableWidget::ULyraActivatableWidget(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
}

TOptional<FUIInputConfig> ULyraActivatableWidget::GetDesiredInputConfig() const
{
	switch (InputConfig)
	{
	case ELyraWidgetInputMode::GameAndMenu:
		return FUIInputConfig(ECommonInputMode::All, GameMouseCaptureMode);
	case ELyraWidgetInputMode::Game:
		return FUIInputConfig(ECommonInputMode::Game, GameMouseCaptureMode);
	case ELyraWidgetInputMode::Menu:
		return FUIInputConfig(ECommonInputMode::Menu, EMouseCaptureMode::NoCapture);
	case ELyraWidgetInputMode::Default:
	default:
		return TOptional<FUIInputConfig>();
	}
}

#if WITH_EDITOR

void ULyraActivatableWidget::ValidateCompiledWidgetTree(const UWidgetTree& BlueprintWidgetTree, class IWidgetCompilerLog& CompileLog) const
{
	Super::ValidateCompiledWidgetTree(BlueprintWidgetTree, CompileLog);

	if (!GetClass()->IsFunctionImplementedInScript(GET_FUNCTION_NAME_CHECKED(ULyraActivatableWidget, BP_GetDesiredFocusTarget)))
	{
		if (GetParentNativeClass(GetClass()) == ULyraActivatableWidget::StaticClass())
		{
			CompileLog.Warning(LOCTEXT("ValidateGetDesiredFocusTarget_Warning", "GetDesiredFocusTarget wasn't implemented, you're going to have trouble using gamepads on this screen."));
		}
		else
		{
			//TODO - Note for now, because we can't guarantee it isn't implemented in a native subclass of this one.
			CompileLog.Note(LOCTEXT("ValidateGetDesiredFocusTarget_Note", "GetDesiredFocusTarget wasn't implemented, you're going to have trouble using gamepads on this screen.  If it was implemented in the native base class you can ignore this message."));
		}
	}
}

#endif

#undef LOCTEXT_NAMESPACE

EDIT: Also, you can add a “false” to the end of the inputconfig function calls (its true by default) if you don’t want the mouse disappearing on capture.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.