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

**URL:** <https://forums.unrealengine.com/t/how-can-i-make-an-actor-with-a-child-actor-in-plugin-c/350570>\
**Category:** Plugins\
**Tags:** parent, actor, child, unreal-engine, Plugins, CPP, question\
**Created:** [March 15, 2016, 7:19am UTC](https://forums.unrealengine.com/t/how-can-i-make-an-actor-with-a-child-actor-in-plugin-c/350570 "2016-03-15T07:19:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_d6ac54c2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d6ac54c2](https://forums.unrealengine.com/u/anonymous_user_d6ac54c2)\
**Post date:** [March 15, 2016, 7:19am UTC](https://forums.unrealengine.com/t/how-can-i-make-an-actor-with-a-child-actor-in-plugin-c/350570/1 "2016-03-15T07:19:02Z")

</div>

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

 ![82221-parentchild.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/6/c/76c881af137e2d3aa9e6749c3ded4cf282da2931.jpeg)

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.

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [March 15, 2016, 3:57pm UTC](https://forums.unrealengine.com/t/how-can-i-make-an-actor-with-a-child-actor-in-plugin-c/350570/2 "2016-03-15T15:57:24Z")

</div>

Use the ChildActorComponent:  
[link text](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UChildActorComponent/index.html)

And the CreateActorActor function:  
[link text](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UChildActorComponent/CreateChildActor/index.html)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d6ac54c2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d6ac54c2](https://forums.unrealengine.com/u/anonymous_user_d6ac54c2)\
**Post date:** [March 16, 2016, 12:01pm UTC](https://forums.unrealengine.com/t/how-can-i-make-an-actor-with-a-child-actor-in-plugin-c/350570/3 "2016-03-16T12:01:19Z")

</div>

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.

 ![82430-parentchild2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/2/a/52a34a634d697d1fa16c0d70a028fb435f846cb2.jpeg)

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);
}

```

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [March 17, 2016, 2:17pm UTC](https://forums.unrealengine.com/t/how-can-i-make-an-actor-with-a-child-actor-in-plugin-c/350570/4 "2016-03-17T14:17:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d6ac54c2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d6ac54c2](https://forums.unrealengine.com/u/anonymous_user_d6ac54c2)\
**Post date:** [March 18, 2016, 2:24am UTC](https://forums.unrealengine.com/t/how-can-i-make-an-actor-with-a-child-actor-in-plugin-c/350570/5 "2016-03-18T02:24:39Z")

</div>

I understand.

![82743-parentchild3.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/1/9/b19184e19b4e040a4cc69ed268a9f2060e18e0a0.jpeg)

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();
}

```

---

<div class="post-metadata">

**Author:** ![Maverick\_tango](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Maverick\_tango](https://forums.unrealengine.com/u/Maverick_tango)\
**Post date:** [August 30, 2018, 6:30am UTC](https://forums.unrealengine.com/t/how-can-i-make-an-actor-with-a-child-actor-in-plugin-c/350570/6 "2018-08-30T06:30:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Maverick\_tango](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Maverick\_tango](https://forums.unrealengine.com/u/Maverick_tango)\
**Post date:** [August 30, 2018, 11:47am UTC](https://forums.unrealengine.com/t/how-can-i-make-an-actor-with-a-child-actor-in-plugin-c/350570/7 "2018-08-30T11:47:16Z")

</div>

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