Widget component created by "Add component by class" doesn't receive input even though set "bReceiveHardwareInput" to true

Goal

Dynamicly add any number of widget to character BP. The widget should be fixed at certain location of viewport, so it should be attached to camera component.

Problem

Widget component created by Add component by class doesn’t receive input even though set bReceiveHardwareInput to true.

For example, I create a widget with a button and a image, then the buttion doesn’t respond to my mouse.

bReceiveHardwareInput is protected variable so I create a derived class, new a member function to modify it.

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/WidgetComponent.h"
#include "MyWidgetComponent.generated.h"

/**
 * 
 */
UCLASS()
class MYPROJECT_API UMyWidgetComponent : public UWidgetComponent
{
	GENERATED_BODY()
	
	UFUNCTION(BlueprintCallable, Category = UserInterface)
	void EnableInput(bool bEnable)
	{
		bReceiveHardwareInput = bEnable;
	}
};

My blueprint

https://blueprintue.com/render/jg7chivf/

A description of my blueprint

At the Begin Play event of character BP, use Add component by class node create my derived widget component class, create testing widget, set the testing widget to widget component, call my custom function to set bReceiveHardwareInput to true, attach widget component to camera component, set relative transform of widget component.

My try

I have checked some thread, such as

3D Widget Problem: Buttons onclicked does not Work - Programming & Scripting / UI - Epic Developer Community Forums

His problem simply because of he didn’t set bReceiveHardwareInput to true.

3D Widget Component doesn’t register clicks - Programming & Scripting / Blueprint - Epic Developer Community Forums

His solution about adding collision box doesn’t help.

My guess

If I create widget component in BP editor, then everything is fine, it can receive input.

So I think either I did some wrong about creating component, or attach component incorrectly.

My project on git

CheapMeow/UEWidgetComponentAddedNoInput

UE version

5.5.1

This seems to be working fine with BPs:

  • set widget class on the overridden component and enable hardware input:

  • add it using one of those:

No additional nodes are necessary.


That’s UE v5.3, though.

It works, thank you!
There must be some work between my Add component by class and the solution spawn custom blueprint component which override widget component.
But that is additional talk.

1 Like

You can simply use “Add Widget Component” node, which seems like specialization of “Add component”.

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