SetupAttachment to widget component

Hello
Is it possible to attach USphereComponent to UWidgetComponent?
h

UCLASS()
class TESTPROJECT_API UInteractionComponent : public UWidgetComponent
{
	GENERATED_BODY()
	
public:
	UInteractionComponent();

	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
	class USphereComponent* InteractionTriggerSphere;

cpp

UInteractionComponent::UInteractionComponent()
{
	InteractionTriggerSphere = CreateDefaultSubobject<USphereComponent>(TEXT("InteractionTriggerSphere"));
	InteractionTriggerSphere->SetupAttachment(this);

result

image

A can attach for example a box manually to the InteractionComponent in the BP, but using C++ I get a strange result.
I’ll appreciate it if somebody could tell me what I’m doing wrong.

1 Like

Hi Zmtrk,

It could be because the InteractionComponent is a Widget - I’ve never tried it, but it stood out as being a possible issue.

Thank you for your response, RecourseDesign
Yeah, I’m thinking about that. But if it could be done in BP, maybe there is a way in c++ too.
And in my example, it’s too soon, or too late, or the wrong place, I don’t know.

The most strange part is that the trigger sphere trying to attach to itself. But as I understand this in SetupAttachment(this) is referenced to the interaction component.

Ok, apparently it was just weird behaviour of UE. I’ve added component to the actor, compiled, deleted it, and now everything looks as it’s supposed to look.

1 Like