# Spawn empty actor

**URL:** <https://forums.unrealengine.com/t/spawn-empty-actor/309560>\
**Category:** C++\
**Tags:** empty, unreal-engine, CPP, question\
**Created:** [March 6, 2015, 5:57am UTC](https://forums.unrealengine.com/t/spawn-empty-actor/309560 "2015-03-06T05:57:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7587ca9c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7587ca9c](https://forums.unrealengine.com/u/anonymous_user_7587ca9c)\
**Post date:** [March 6, 2015, 5:57am UTC](https://forums.unrealengine.com/t/spawn-empty-actor/309560/1 "2015-03-06T05:57:44Z")

</div>

Hello, how i can spawn an empty actor using c++?

I’m trying to use this:

SpawnActor(AActor::GetClass(),GetActorLocation(),GetActorRotation());

but its seems to not working. I cant find object in object outliner and add components to it.

---

<div class="post-metadata">

**Author:** ![trutty](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@trutty](https://forums.unrealengine.com/u/trutty)\
**Post date:** [March 7, 2015, 1:25am UTC](https://forums.unrealengine.com/t/spawn-empty-actor/309560/2 "2015-03-07T01:25:04Z")

</div>

I don’t understand what you want to achieve with this empty actor, but I guess you can only spawn an actor class which inherits from `AActor` and is not the base class `AActor` itself. Try making a new actor class using `File | Add Code To Project...` in the Editor and choose `AActor` as the base class. In C++ use

```
()->SpawnActor<AMyActor>(AMyActor::StaticClass());

```

from e.g. your `PlayerController` or `GameMode`.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7587ca9c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7587ca9c](https://forums.unrealengine.com/u/anonymous_user_7587ca9c)\
**Post date:** [March 8, 2015, 3:08am UTC](https://forums.unrealengine.com/t/spawn-empty-actor/309560/3 "2015-03-08T03:08:38Z")

</div>

I will try it, thanks

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [March 8, 2015, 3:34am UTC](https://forums.unrealengine.com/t/spawn-empty-actor/309560/4 "2015-03-08T03:34:18Z")

</div>

It seems indeed

```
else if( !Class->IsChildOf(AActor::StaticClass()) )
{
	UE_LOG(LogSpawn, Warning, TEXT("SpawnActor failed because %s is not an actor class"), *Class->GetName() );
	return NULL;
}

```

IsChildOf probably return false on parent itself. Check the logs to confirm that

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8ab98422](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8ab98422](https://forums.unrealengine.com/u/anonymous_user_8ab98422)\
**Post date:** [July 13, 2015, 10:10pm UTC](https://forums.unrealengine.com/t/spawn-empty-actor/309560/5 "2015-07-13T22:10:59Z")

</div>

An empty actor can be usefull to act as source and target for a dynamically spawned Particle System and so on…

But if you really need one you need a Empty Actor class. AActor alone is not equipped with a scene component. So it can not be positioned in the scene.

Declare the AEmptyActor Class like this

```
#pragma once

#include "GameFramework/Actor.h"
#include "EmptyActor.generated.h"

UCLASS()
class YOURGAME_API AEmptyActor : public AActor
{
	GENERATED_BODY()
public:	
	AEmptyActor(const FObjectInitializer& ObjectInitializer);

	UPROPERTY()
	class USceneComponent* Scene;
};

```

and define it like that

```
#include "YourGame.h"
#include "EmptyActor.h"

AEmptyActor::AEmptyActor(const FObjectInitializer& ObjectInitializer) :
	Super(ObjectInitializer)
{
	PrimaryActorTick.bCanEverTick = false;
	
	Scene = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("Scene"));
	Scene->SetMobility(EComponentMobility::Movable);
	SetRootComponent(Scene);
}

```

After that you can simply spawn it

```
()->SpawnActor(AEmptyActor::StaticClass());

```
