# Why i have error the spawn actor?

**URL:** <https://forums.unrealengine.com/t/why-i-have-error-the-spawn-actor/359359>\
**Category:** C++\
**Tags:** unreal-engine, crash, CPP, question\
**Created:** [June 2, 2016, 11:19am UTC](https://forums.unrealengine.com/t/why-i-have-error-the-spawn-actor/359359 "2016-06-02T11:19:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_23644fc6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_23644fc6](https://forums.unrealengine.com/u/anonymous_user_23644fc6)\
**Post date:** [June 2, 2016, 11:19am UTC](https://forums.unrealengine.com/t/why-i-have-error-the-spawn-actor/359359/1 "2016-06-02T11:19:00Z")

</div>

i try spawn from GameInstance.

GameInstance cpp:

```
UMyGameInstance::UMyGameInstance()

{
	
	static ConstructorHelpers::FClassFinder<AGameObject> Character(TEXT("/Game/Blueprints/Game/BP_Object"));
	if (Character.Class != NULL)
	{
		GameObject = Character.Class;
	}
}

void UMyGameInstance::SpawnObjectsFromArray()

{

UWorld* const World = GetWorld();

	if (World)
	{
		const FVector& Location = FVector(0.0f, 0.0f, 148.0f);
		const FRotator& Rotation = FRotator();
		FActorSpawnParameters SpawnParams;

		World->SpawnActor<AActor>(GameObject, Location, Rotation, SpawnParams);

	}
}

```

GameInstance h:

```
public:

	TSubclassOf<class AGameObject> GameObject;

```

After launch the game i have error window.

 ![92991-screenshot_3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/e/b/7eb17d1fbe7b556874c37d618bd4ebc82cc17c5e.png)

---

<div class="post-metadata">

**Author:** ![Nachtmahr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nachtmahr](https://forums.unrealengine.com/u/Nachtmahr)\
**Post date:** [June 2, 2016, 9:25pm UTC](https://forums.unrealengine.com/t/why-i-have-error-the-spawn-actor/359359/2 "2016-06-02T21:25:35Z")

</div>

Try checking for Null and switch from AActor to AGameObject as template

```
if(GameObject->GetClass())
World->SpawnActor<AGameObject>(GameObject->GetClass(), Location, Rotation, SpawnParams);

```

Also set the Rotator to FRotator::ZeroRotator instead of leaveing it Unitialized. You also dont need the “&” on your FVector and FRotator.

I dont See anything else that can cause trouble.
