C++ Components with sub components

Find a weird thing : When use CreateDefaultSubobject(TEXT(“CaptureCamera”));, the camera can’t follow parent component’s transform. But when add the camera to a Arrow in SceneComponent’s constructor, the camera can follow parent component’s transform. So weird…

UAAAComponent::UAAAComponent():
{
// 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;
FakeRoot = CreateDefaultSubobject(TEXT(“Arrow”));
FakeRoot->SetupAttachment(this);

Camera = CreateDefaultSubobject(TEXT(“Camera”));
Camera->AttachToComponent(Arrow, FAttachmentTransformRules::KeepRelativeTransform);
}

1 Like