SphereComponent Not Appearing in Components Tab When Added via ActorComponent

Hi everyone,

I’ve been working on a project in Unreal Engine and ran into an issue when trying to add a SphereComponent via an ActorComponent. While the SphereComponent is visible in the viewport, it doesn’t appear in the Components tab of the Blueprint Editor.

Here’s a summary of my setup:

MyActorComponent.h

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "MyActorComponent.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYPROJECT_API UMyActorComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UMyActorComponent();

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
	class USphereComponent* Collider;

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

		
};

MyActorComponent.cpp

#include "MyActorComponent.h"

#include "Components/SphereComponent.h"

// Sets default values for this component's properties
UMyActorComponent::UMyActorComponent()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
	Collider = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere"));
	if (AActor* Owner = GetOwner())
	{
		Collider->SetupAttachment(Owner->GetRootComponent());
		Collider->RegisterComponent();
	}
}


// Called when the game starts
void UMyActorComponent::BeginPlay()
{
	Super::BeginPlay();

	// ...
	
}


// Called every frame
void UMyActorComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// ...
}

and this is what happen:

Despite these steps, the SphereComponent is only visible in the viewport but not listed in the Components tab.

I also tried google and found some threads saying it’s a UE 4.x bug
but I’m using UE 5.4.4

Any insights or suggestions on what might be missing or misconfigured would be greatly appreciated!

Thank you!

AFAIK doing this shouldn’t really even work. Inside the UMyActorComponent constructor, you should not touch anything that’s outside of this component, such as the owning actor, because in a sense it does not have one. You will either have to move this code to the relevant owning actor class, where you can use your approach or spawn the scene component at runtime, such as inside BeginPlay(). Alternatively, if the spawning component itself was a scenic component, you could spawn and attach the spawned component to it the way you did it.

You are right. After a day of googling, I just found out that creating a component inside a component constructor is strictly used so i need to upgrade my game architecture to fit.

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