Unload Level does not Destroy Actors

I tried to use UnloadLevel node in blueprint and call it in my PlayerController blueprint. For some reason, every actor made statically (by inserting via Editor), gets destroyed. But all actors dynamically created and spawned in that level, via blueprint, do not get destroyed. Why?

Hey Pelangi,

Could you do me a favor and double check that the actors that are not being destroyed are definitely part of the level that is being unloaded? Is it possible that these actors are being spawned in the persistent or other level instead of the level that you are unloading?

I’ll try to give the steps as best as I can to replicate this. The target platform is for smartphones.

  1. For example, let’s say I have 3 levels: ParentLevel, ChildLevel1, and ChildLevel2.
  2. ParentLevel is the persistent level.
  3. ChildLevel1 is a sibling of ChildLevel2. They both are inside ParentLevel.
  4. Create a simple custom widget, let’s say UMyWidget. Inside it, just add a simple image, via editor, and implement the OnTouchEnd event in UMyWidget blueprint. Inside OnTouchEnd, unload ChildLevel1 and load stream ChildLevel2.
  5. In level blueprint for ParentLevel, I unload ChildLevel2 and load stream ChildLevel1. It is done inside BeginPlay event.
  6. Inside ChildLevel1, I inserted a simple actor, via Editor, which consist of a single static mesh. Let’s say it is ABox.
  7. Inside ABox blueprint, I implement the OnInputTouchEnd event. Inside it, I spawn another actor, let’s say ABall.
  8. Inside ABall blueprint, I implement the OnInputTouchEnd event. Inside it, I call CreateWidget node to create UMyWidget and then call node AddToViewport, to put it on the screen.
  9. Play the game!
  10. Click ABox then click ABall then click the image inside UMyWidget.
  11. Notice that ABall is not destoryed.

Thanks for the steps, I’ve found that simply unloading a streamed level with a dynamically spawned actor does not destroy the actor.

I have entered a bug report for this, which you can track here:

Thanks for your report.

Have a great day

The bug report says that it has been resolved, but I’m still having issues with this bug in 4.14 and 4.15. Is it not fixed yet?

The bug is marked as By Design. The reason is that spawned actors are in the ‘persistent’ level and will not automatically go away when levels are streamed out.

That’s dev code for they are not going to bother fixing it, I assume, as no one would actually design the system that way.

I look the bug marked as by design, so how to I design it can let the actor destroy when level stream unload. the actor spawn in child level bp, so i want when the child level unload , the actor instance also can destroy. how to deign ?

for me this is a problem…i have been using get all actors of class and then destroy actor…for each actor class that is in the scene…i have been getting other problems also when trying to unload streaming levels while using ai behaviour kit…even though i get all actors of class and delete them…over time performance drops because when deleting ai with collision spheres for mele…the actors are deleted but not the collision spheres…and even though i get all actors of class and delete the collision spheres…the peerfomrance still drops over time after streaming levels back and forth…maybe the actor is still referenced…but ■■■■…if it would just delete actors that exist on the level that would be nice

Spawning an actor from within the sublevel blueprint is not sufficient to bind the actor lifetime to that of the level, what you have to do is assign an owner to the new actor (in blueprint editor expand the spawn node to reveal the Owner pin). When you don’t specify an owner explicitly, the persistent level is used by default. On the other hand, if you plug any actor owned by that sublevel (or the sublevel itself) into the owner pin, the spawned actor should be destroyed correctly when the level is unloaded. You can for instance place an empty actor in the sublevel and pass it as owner to the spawn node (this can be easily wrapped inside a dedicated blueprint).

Hope it helps

It would be great if someone could expand on how to “pass it as the owner to the spawn node” – I can seen the owner node in the SpawnActor but how to get a reference to an actor that is in the level? in the level blueprint?

I realize it’s been a while since this question has been asked, but I’ll show you my findings regardless.
I’ve been working on a game that uses smaller levels which are streamed in as the player gets close. In these test levels, I wanted to be able to spawn actors in dynamically, and have them despawn when the player gets too far. I made a blueprint which line traces directly downward, seeking a solid object. When this object (the landscape) was hit, the game would spawn in the barrels I made, but upon unloading the level, the barrels would persist—suspended in the void which the absent level created.

Using the hit result from the line trace, you can take the actor which was hit and set it as the barrel’s “owner”. Exactly like Mercanti said, it seems to have sent the barrels to the proper level, and they now despawn properly along with the level.

Still broken in 4.27.

Actors are 100% children of a streaming level.

Some emitters persist after unload.

Any actor modified (movement/resize/etc) persists after unload.