UBoxComponent not visible in Child Blueprint class

Dear experts,

I have a UBoxComponent on a class called Interactable:

//box component for line traces
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UBoxComponent* LineTraceBox;

and in the .cpp I have

// Sets default values
AInteractable::AInteractable()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	//PrimaryActorTick.bCanEverTick = true;
	Name = "Interactable";
	Action = "interact";

	FVector TriggerBoxSize = FVector(30.0f,30.0f,30.0f);
	//we add this box to our interactable objects.
	//sometimes the mesh is really small (cups for example) and hard to hit: the box is bigger and easier to hit
	LineTraceBox = CreateDefaultSubobject<UBoxComponent>(TEXT("LineTraceBox"));
	LineTraceBox->SetBoxExtent(TriggerBoxSize);
	LineTraceBox->SetupAttachment(RootComponent);
	LineTraceBox->SetCollisionEnabled(ECollisionEnabled::QueryOnly); //we only need it for the line trace
	LineTraceBox->SetCollisionResponseToAllChannels(ECR_Block);

}

Now I have another class inheriting from this base class like this:

class MYTEST AManPickup : public AInteractable

And now I have a blueprint based on the MYTEST C++ class and I can see my Box component and I set it so it shows when I play:

But when I actually play I can’t see the box:

noboxwhenIplay

What am I missing here? I feel like something with my inheritance is not okay. Is my UPROPERTY in the base class okay? UPROPERTY(EditAnywhere, BlueprintReadWrite)

Thank you, Peter

EDIT: So what I just did, I went into the BP class and manually added another UBoxComponent, and that works, look at the shots:

So why does it not work when adding the UBoxComponent to the Parent C++ ?
I don’t get it

This should be VisibleAnywhere, BlueprintReadOnly. And why it is not showing the box, I have no idea. But first change that. Maybe something else is setting to hidden.

1 Like

Hello KaosSpectrum,

Thank you, I fixe that.

And to my problem. I got it now:
The problem was that the UStaticMeshComponent I had added to the child C++ class.
But the box component I had added to the parent C++ class. And I added the UBoxComponent
to the root like so:

LineTraceBox->SetupAttachment(RootComponent);

But there was no root component in the C++ parent.

So now I moved the UStaticMeshComponent to the parent C++ class and made that the root

RootComponent = Cast<USceneComponent>(PickupMesh);

And now the UBoxComponent is properly attached in the C++ parent and the box is visible in gameplay. Stupid mistake…

Kind regards,
Peter