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
His problem simply because of he didn’t set bReceiveHardwareInput
to true.
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