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.
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.
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.
answered Mar 01 '18 at 03:45 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here