Widget is not creating an input component.

Summary

I’m using enhanced input in C++ to control my widget.
To enable auto register for that widget I’m setting bAutomaticallyRegisterInputOnConstruction to true in the constructor but this gets overridden during blueprint compile leading to not creating an input component for the widget and not receiving input on the widget.

What Type of Bug are you experiencing?

Foundation (C++ Tools, Profiling, & Pipeline)

Steps to Reproduce

  • Create a C++ class inheriting from UCommonActivatableWidget.
  • Set bAutomaticallyRegisterInputOnConstruction to true in the constructor.
  • Look into it at runtime and see that bAutomaticallyRegisterInputOnConstruction is false

Expected Result

bAutomaticallyRegisterInputOnConstruction to stay true when I set it to true in the constructor.

Observed Result

bAutomaticallyRegisterInputOnConstruction is false during runtime

Affects Versions

5.8

Platform(s)

Windows

Additional Notes

The problem is in

void FWidgetBlueprintCompilerContext::CopyTermDefaultsToDefaultObject(UObject* DefaultObject)

this sets it to false when no blueprint needs input

// If either this BP or any of its parents require the input registration then we want to use it
DefaultWidget->bAutomaticallyRegisterInputOnConstruction = bRequiresInputEvents || bParentRequiresInputReg;

suggested solution

// If either this BP or any of its parents require the input registration then we want to use it
DefaultWidget->bAutomaticallyRegisterInputOnConstruction |= bRequiresInputEvents || bParentRequiresInputReg;

keep it on true if it’s already true.

For now I added a workaround to reset bAutomaticallyRegisterInputOnConstruction after blueprint compile

void USC_ActivatableCircleMenuWidget::PostCDOCompiled(const FPostCDOCompiledContext& Context)
{
    Super::PostCDOCompiled(Context);

    // Reset auto register to true after blueprint compiler nukes it 
    bAutomaticallyRegisterInputOnConstruction = true;
}