# SpawnActor returns null because actor is "pending kill"

**URL:** <https://forums.unrealengine.com/t/spawnactor-returns-null-because-actor-is-pending-kill/418688>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 1, 2018, 3:31pm UTC](https://forums.unrealengine.com/t/spawnactor-returns-null-because-actor-is-pending-kill/418688 "2018-03-01T15:31:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herr\_Edgy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/herr_edgy/32/924115_2.png) [@Herr\_Edgy](https://forums.unrealengine.com/u/Herr_Edgy)\
**Post date:** [March 1, 2018, 3:31pm UTC](https://forums.unrealengine.com/t/spawnactor-returns-null-because-actor-is-pending-kill/418688/1 "2018-03-01T15:31:01Z")

</div>

I’m trying to implement an “actor transfer” function that saves an actor in a record, then changes the level, then loads the actor in via spawning him by using the record.

When I try to spawn the actor by using “SpawnActor” method, the actor it’s creating is “pending kill”, so it returns null.  
Why is that? The function gets called once the new level is loaded and I am trying to spawn an actor, so I don’t get why it would be pending kill.

Can anyone explain why an actor spawned by SpawnActor method would actually be pending kill?

EDIT:  
I have set the bNoFail member of SpawnParameters to true, and it gets rid of that problem. However, the actor obviously still is pending kill (and I think gets deleted immediately?). So the actor doesn’t seem to spawn. Howevero, the camera spawns at 0,0,0 of my new level, so apparently the transform doesn’t get applied either? It’s all very confusing.

---

<div class="post-metadata">

**Author:** ![GIGA-Money](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GIGA-Money](https://forums.unrealengine.com/u/GIGA-Money)\
**Post date:** [March 1, 2018, 3:45pm UTC](https://forums.unrealengine.com/t/spawnactor-returns-null-because-actor-is-pending-kill/418688/2 "2018-03-01T15:45:20Z")

</div>

Well try to understand garbage collection first : see here

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

and

> **[Unreal Object Handling](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Objects/Optimizations/)**
>
> Overview of the features of the UObject system.

**Actors** and their **Components** are frequently an exception to this, since the **Actors are usually referenced** by an _Object_ that _links back to the root set,_ such as the Level to which they belong, and the Actor’s Components are referenced by the Actor itself. Actors can be explicitly marked for destruction by calling their Destroy function, which is the standard way to remove an Actor from an in-progress game. Components can be destroyed explicitly with the DestroyComponent function, but they are usually destroyed when their owning Actor is removed from the game.

IE: something might not be getting deleted correctly. or in the correct order.

---

<div class="post-metadata">

**Author:** ![Herr\_Edgy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/herr_edgy/32/924115_2.png) [@Herr\_Edgy](https://forums.unrealengine.com/u/Herr_Edgy)\
**Post date:** [March 1, 2018, 4:03pm UTC](https://forums.unrealengine.com/t/spawnactor-returns-null-because-actor-is-pending-kill/418688/3 "2018-03-01T16:03:33Z")

</div>

I will give it a read, thanks.

However, my problem is not that something doesn’t get “deleted” correctly; the actor that is supposed to spawn is determined to be “pending kill” from the get go.  
The line I use is the following.

```
AActor * actor = GetWorld()->SpawnActor<AActor>(record.ActorClass, record.ActorTransform, SpawnParameters);

```

The first two parameters are valid values from the last level. The third one is a freshly created SpawnParameters object with only the name set (and the bNoFail as an experiment).  
This all happens after the level has been loaded, as it gets called by Begin Play of the level blueprint.

If you don’t specify the owner etc. of the SpawnParameters, the persistent level gets used as the outer object (the root set in your words, I guess). It’s really irritating as I don’t see a reason why it should not be able to be spawned.

---

<div class="post-metadata">

**Author:** ![Herr\_Edgy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/herr_edgy/32/924115_2.png) [@Herr\_Edgy](https://forums.unrealengine.com/u/Herr_Edgy)\
**Post date:** [March 1, 2018, 4:09pm UTC](https://forums.unrealengine.com/t/spawnactor-returns-null-because-actor-is-pending-kill/418688/4 "2018-03-01T16:09:37Z")

</div>

I found out the reason why. Still thank you to GIGA-Money, as that link is helpful!

The actor does not get spawned because the spawning location was blocked. I intentionally tested a “proper” location, but it seems like the system still didn’t like that one. I now set the Spawn Collision Handling Method to “Always spawn” and it worked properly.

I thought that the bNoFail flag would be responsible to spawn the actor no matter what, turns out it doesn’t.

My log was full because of error messages. When I scrolled up I found the message informing me about the spawn location being blocked.

---

<div class="post-metadata">

**Author:** ![FusionAura](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FusionAura](https://forums.unrealengine.com/u/FusionAura)\
**Post date:** [January 10, 2019, 6:16am UTC](https://forums.unrealengine.com/t/spawnactor-returns-null-because-actor-is-pending-kill/418688/5 "2019-01-10T06:16:01Z")

</div>

Wasted so much time trying to fix it and it was something so simple. Thank You!

---

<div class="post-metadata">

**Author:** ![Anonymous\_14178ea5fb3e8ff67cba83009ca0e6b6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_14178ea5fb3e8ff67cba83009ca0e6b6](https://forums.unrealengine.com/u/Anonymous_14178ea5fb3e8ff67cba83009ca0e6b6)\
**Post date:** [January 27, 2021, 3:16pm UTC](https://forums.unrealengine.com/t/spawnactor-returns-null-because-actor-is-pending-kill/418688/6 "2021-01-27T15:16:56Z")

</div>

Yes I also waste too much time, resove it after changing the “Collision Default” of a blueprint actor.Thanks you for your idea.
