Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

SpawnActor returns null because actor is "pending kill"

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.

Product Version: UE 4.18
more ▼

asked Mar 01 '18 at 03:31 PM in C++ Programming

avatar image

79 6 11 17

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Mar 01 '18 at 04:09 PM

avatar image

79 6 11 17

avatar image FusionAura Jan 10 '19 at 06:16 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Well try to understand garbage collection first : see here https://wiki.unrealengine.com/Garbage_Collection_Overview and https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Objects/Optimizations/

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.

more ▼

answered Mar 01 '18 at 03:45 PM

avatar image

237 2 11 6

avatar image Quexlaw Mar 01 '18 at 04:03 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question