# UE4 Actor constructor

**URL:** <https://forums.unrealengine.com/t/ue4-actor-constructor/291083>\
**Category:** Platform & Builds\
**Tags:** actor, classes, initialize, unreal-engine, UE4, question\
**Created:** [August 15, 2014, 9:35pm UTC](https://forums.unrealengine.com/t/ue4-actor-constructor/291083 "2014-08-15T21:35:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheTrice](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheTrice](https://forums.unrealengine.com/u/TheTrice)\
**Post date:** [August 15, 2014, 9:35pm UTC](https://forums.unrealengine.com/t/ue4-actor-constructor/291083/1 "2014-08-15T21:35:05Z")

</div>

So i Wanted an actor class to contain another actor , so i have 2 actors one called Aapples and ATree.

Aapples is just a actor generated code by editor.

Atree code here it is :

```
#include "apple.h"
#include "GameFramework/Actor.h"
#include "Tree.generated.h"
UCLASS()
class ATree : public AActor
{
	
public:

	Aapple apples[100]

GENERATED_UCLASS_BODY()
};

```

this generates this error : `Error 1 error : In Tree: Missing ‘\*’ in Expected a pointer type

So i replaced it with pointers to object so later i can initalize them in my code so i changed it to :  
Aapple\* apples[100]

But i dont know how to initalize apples in the code i tried this in Tree.cpp :  
in middle of code:  
apple[0] = new Aapple();

ofcourse there is no constructor with this arguments as all actor constructors are like this :

```
  Aapple::Aapple(const class FPostConstructInitializeProperties& PCIP)
    	: Super(PCIP)
    {
    
    }

```

So i tried this  
apples[0]= new Aapple(PCIP);  
but PCIP is not defiend , so how do i initalize an acotr class ?

---

<div class="post-metadata">

**Author:** ![James\_Ordner](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@James\_Ordner](https://forums.unrealengine.com/u/James_Ordner)\
**Post date:** [August 22, 2014, 1:43pm UTC](https://forums.unrealengine.com/t/ue4-actor-constructor/291083/2 "2014-08-22T13:43:59Z")

</div>

apples[0] = GetWorld()-\>SpawnActor(AApple::StaticClass());  
Also, make sue you call that in BeginPlay() and not the constructor, because the world will not be valid in the constructor and crash.

---

<div class="post-metadata">

**Author:** ![TheTrice](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheTrice](https://forums.unrealengine.com/u/TheTrice)\
**Post date:** [August 25, 2014, 3:38am UTC](https://forums.unrealengine.com/t/ue4-actor-constructor/291083/3 "2014-08-25T03:38:11Z")

</div>

Thanks!! James
