# Children of my custom USceneComponent do not use parents transform

**URL:** <https://forums.unrealengine.com/t/children-of-my-custom-uscenecomponent-do-not-use-parents-transform/2310475>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [January 30, 2025, 3:49pm UTC](https://forums.unrealengine.com/t/children-of-my-custom-uscenecomponent-do-not-use-parents-transform/2310475 "2025-01-30T15:49:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dakxon2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dakxon2](https://forums.unrealengine.com/u/Dakxon2)\
**Post date:** [January 30, 2025, 3:49pm UTC](https://forums.unrealengine.com/t/children-of-my-custom-uscenecomponent-do-not-use-parents-transform/2310475/1 "2025-01-30T15:49:44Z")

</div>

I am having trouble setting up a custom `USceneComponent` and attaching it to my Pawn. I am trying to create the following hierarchy of components in my Pawns blueprint:

BP\_BirdseyePawn - Inherits from `ABirdseyePawn : public APawn`:  
-SceneComponent (RootComponent)  
– UCameraMovementComponent (Custom USceneComponent)  
—UStaticMeshComponent

I am having an issue where the `UStaticMeshComponent` does not follow the transform of the `UCameraMovementComponent`. When I move the `UCameraMovementComponent` the `UStaticMeshComponent` does not move at all.

The `UStaticMeshComponent` looks correctly attached to the `UCameraMovementComponent` in the blueprint editor:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/6/e/16ef25dc4f7347c3403912ad7f0958879019e425.png)

However, during runtime I can see in the outliner that the mesh component is not a child of the `UCameraMovementComponent`:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/4/e/c4e5559ba1ba386b11f4ae61847872908a46072f.png)

If I drag a new static mesh component into the blueprint editor manually (i.e not inherited from c++) then the transforms are respected as I expect:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/0/60042c2885e7d785029a2179e63066e3884c27e2.jpeg)

And in the outliner I see that this is also the case:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/6/4/c64352d6dd03d6de7f5be5b330978857e822f22e.png)

My classes are setup as follows:

ABirdseyePawn:

```auto
UCLASS()
class TOWERTYCOON_API ABirdseyePawn : public APawn
{
	GENERATED_BODY()

public:

	ABirdseyePawn();

public:	

	virtual void Tick(float DeltaTime) override;

	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
	
	virtual void BeginPlay() override;

protected:

	UPROPERTY(EditDefaultsOnly)
	USceneComponent* view_target_;

	UPROPERTY(EditDefaultsOnly)
	UCameraMovementComponent* cam_movement_component_;
};

ABirdseyePawn::ABirdseyePawn()
{
	PrimaryActorTick.bCanEverTick = true;	

	//Root Component
	view_target_ = CreateDefaultSubobject<USceneComponent>(FName("PawnRoot"));
	view_target_->bAutoActivate = true;
	view_target_->bAutoRegister = true;
	this->SetRootComponent(view_target_);

	//Camera Movement Component
	cam_movement_component_ = CreateDefaultSubobject<UCameraMovementComponent>(FName("CameraMovement"));
	cam_movement_component_->bAutoActivate = true;
	cam_movement_component_->bAutoRegister = true;
	cam_movement_component_->SetupAttachment(RootComponent);
}

void ABirdseyePawn::BeginPlay()
{
	Super::BeginPlay();
}

// Called every frame
void ABirdseyePawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

void ABirdseyePawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
}

```

ACameraMovementComponent:

```auto
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class TOWERTYCOON_API UCameraMovementComponent : public USceneComponent
{
	GENERATED_BODY()

public:	
	UCameraMovementComponent();

protected:
	virtual void BeginPlay() override;	

	UPROPERTY(EditDefaultsOnly, Category = Camera)
	UStaticMeshComponent* mesh_;

public:	
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
		
};

UCameraMovementComponent::UCameraMovementComponent()
{
	PrimaryComponentTick.bCanEverTick = true;
	PrimaryComponentTick.SetTickFunctionEnable(true);

	mesh_ = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
	mesh_->bAutoActivate = true;
	mesh_->bAutoRegister = true;
	mesh_->SetupAttachment(this);
}

void UCameraMovementComponent::BeginPlay()
{
	Super::BeginPlay();
}

void UCameraMovementComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}

```

Can anybody help me understand what is going on here?

---

<div class="post-metadata">

**Author:** ![Dakxon2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dakxon2](https://forums.unrealengine.com/u/Dakxon2)\
**Post date:** [January 31, 2025, 9:24am UTC](https://forums.unrealengine.com/t/children-of-my-custom-uscenecomponent-do-not-use-parents-transform/2310475/2 "2025-01-31T09:24:49Z")

</div>

I have found the answer to my problem in this post:

> [@UE5 Template Mismatch During Attaching of Instanced Component](https://forums.unrealengine.com/t/ue5-template-mismatch-during-attaching-of-instanced-component/1510733):
>
> Hello Unreal Engine Community, I’m encountering a problem with my Unreal Engine 5 project and could really use some help. I have a Blueprint named BP\_VRPawn which is derived from a C++ class AVRPawn. The main issue is that the Skeletal Mesh representing the hands is not being attached to the MotionControllers. Another issue is that the first time I open the folder containing BP\_VRPawn, or the first time I open the Blueprint itself, the Visual Studio debugger stops, and I receive the following l…

My understanding of the problem is as follows:

In the constructor of my `UCameraMovementComponent` I set attachement to `this`:

```auto
UCameraMovementComponent::UCameraMovementComponent()
{
	PrimaryComponentTick.bCanEverTick = true;
	PrimaryComponentTick.SetTickFunctionEnable(true);

	mesh_ = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
	mesh_->bAutoActivate = true;
	mesh_->bAutoRegister = true;
	mesh_->SetupAttachment(this);
}

```

When the CDO of my class is constructed, `this` is pointing to the CDO and not the specific instance of my class. Since `mesh_` is a UPROPERTY it will be get replaced in the actual instance after construction with the version from the CDO. This means my class instance has a `mesh_` that is attached to the CDO, and not my instance.

To Solve this issue I need to reattach the `mesh_` to the correct parent when the component is registered (after the CDO values are copied)

```auto
void UCameraMovementComponent::OnRegister() {
    Super::OnRegister();
    this->mesh_->AttachToComponent(this, FAttachmentTransformRules::KeepRelativeTransform);
}

```

With this addition the component works as expected.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [March 2, 2025, 9:25am UTC](https://forums.unrealengine.com/t/children-of-my-custom-uscenecomponent-do-not-use-parents-transform/2310475/3 "2025-03-02T09:25:05Z")

</div>

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