How can I make an actor with a child actor in plugin? [c++]

I create the custom actor ‘Parent Actor’ and ‘Child Actor’.
So, I can set parent/child relationship on UE4 Editor like the following picture.

Then, I want to make a custom actor with child actor in plugin.
How can I make this?

Child Actor header

#pragma once
#include "GameFramework/Actor.h"
#include "TestSampleChildActor.generated.h"

UCLASS(ClassGroup = TestSample, BlueprintType, Blueprintable)
class ATestSampleChildActor : public AActor
{
	GENERATED_UCLASS_BODY()

};

Child Actor code

#include "TestSamplePrivatePCH.h"
#include "TestSampleChildActor.h"

ATestSampleChildActor::ATestSampleChildActor(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	
}

Parent Actor header

#pragma once
#include "GameFramework/Actor.h"
#include "TestSampleParentActor.generated.h"

UCLASS(ClassGroup = TestSample, BlueprintType, Blueprintable)
class ATestSampleParentActor : public AActor
{
	GENERATED_UCLASS_BODY()

	// I want to set child ATestSampleChildActor class.
	//UCLASS()
	//class ATestSampleChildActor* TestSampleChildActor;
};

Parent Actor code

#include "TestSamplePrivatePCH.h"
#include "TestSampleParentActor.h"

ATestSampleParentActor::ATestSampleParentActor(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	// I want to set child ATestSampleChildActor class.
	// ...
}

Thank you.

Use the ChildActorComponent:
link text

And the CreateActorActor function:
link text

Thank you, BrUnO XaVIeR.

I tried your hint.
But, It became a result that is not expected.

  1. It is necessary to attach the Child Actor Instance (BP_Child).
  2. Child Actor’s property is not appeared in Details.

I expect the following behavior.

  1. Create the Parent Actor(BP_Parent) on Editor.
  2. The Parent Actor has a Child Actor (ex. BP_Child) on Editor and Details.

So, It looks like the ‘parentchild.jpg’.

Is this understanding mistaken?

Child Actor’s property (ChildFloatPoint)

UCLASS(ClassGroup = TestSample, BlueprintType, Blueprintable)
class ATestSampleChildActor : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(Category = ChildActorData, EditAnywhere, BlueprintReadWrite)
	float ChildFloatPoint;

public:
	virtual void BeginPlay() override;
};

Parent Actor Class

UCLASS(ClassGroup = TestSample, BlueprintType, Blueprintable)
class ATestSampleParentActor : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(Category = ParentActorData, EditAnywhere, BlueprintReadWrite)
	float ParentFloatPoint;

	UPROPERTY(Category = ExtSample, VisibleAnywhere, BlueprintReadOnly)
	class UChildActorComponent* ChildActorComponent;
};

ATestSampleParentActor::ATestSampleParentActor(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	ChildActorComponent = CreateDefaultSubobject<UChildActorComponent>(TEXT("ChildActorComponent"));
	ChildActorComponent->CreateChildActor();
	ChildActorComponent->AttachTo(RootComponent);
}

If you want details to show on parent actor’s Detail panel, then you have to create an UActorComponent and attach to the actor instead of creating a child Actor.

I understand.

82743-parentchild3.jpg

Thank you for giving me good advice!

TestSampleChildActorComponent.h

#pragma once
#include "TestSampleChildActorComponent.generated.h"

UCLASS(ClassGroup = TestSample, BlueprintType, Blueprintable)
class UTestSampleChildActorComponent : public UActorComponent
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(Category = ChildActorData, EditAnywhere, BlueprintReadWrite)
	float ChildFloatPoint;

public:
	virtual void BeginPlay() override;
};

TestSampleChildActorComponent.cpp

#include "TestSamplePrivatePCH.h"
#include "TestSampleChildActorComponent.h"

UTestSampleChildActorComponent::UTestSampleChildActorComponent(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	
}

void UTestSampleChildActorComponent::BeginPlay()
{
	Super::BeginPlay();

	UE_LOG(LogTestSample, Log, TEXT("ATestSampleChildActorComponent BeginPlay."));
}

TestSampleParentActor .h

#pragma once
#include "GameFramework/Actor.h"
#include "TestSampleParentActor.generated.h"

UCLASS(ClassGroup = TestSample, BlueprintType, Blueprintable)
class ATestSampleParentActor : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(Category = ParentActorData, EditAnywhere, BlueprintReadWrite)
	float ParentFloatPoint;

	UPROPERTY(Category = ExtSample, VisibleAnywhere, BlueprintReadOnly)
	class UActorComponent* ActorComponent;

public:
	virtual void BeginPlay() override;
};

TestSampleParentActor .cpp

#include "TestSamplePrivatePCH.h"
#include "TestSampleParentActor.h"
#include "TestSampleChildActorComponent.h"

ATestSampleParentActor::ATestSampleParentActor(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{	
	ActorComponent = CreateDefaultSubobject<UTestSampleChildActorComponent>(TEXT("TestSampleChildActorComponent"));
	ActorComponent->RegisterComponent();
}

is this working for you ??
Can you please share the code, i want to do the same thing

@BrUnO XaVIeR How to do that ?? via C++ code ??