Unload Stream Level doesn't unload level entirely.

I have a persistent level which loads a TitleLevel then a WorldLevel. Once the player is dead I load the TitleLevel and that’s fine, then I unload the WorldLevel, but the WorldLevel still remain with all actor except the sunlight and atmosphere that has been unloaded.
How can I fix it please?

any help please? :slight_smile:

I’m figuring out that the problem is about Spanwed BP Actors. So should I first create a function to remove them all before unloading the level?

Anything you spawn, gets placed in the persistent level. To avoid this problem, when you spawn, set the owner. That way, when the owner gets destroyed ( your spawner when the level unloads ), so do all the spawned actors.

2 Likes

the problem is that I have many different BP classes . Do you think could be fine if I create a function to search and destroy all actors by class?

You could, but there’s no point. If you set the ‘owner’ pin on spawn, they will disappear when you unload the levl.

A couple of approaches here. Personally, when my player dies, I reload the map; this works fine if you do not mind everything resetting or if you have checkpoint logic or a more complex save/ load logic. Optionally I would say you are on the right track deleting all spawned actors as part of your on death/ reload world logic. I think I did dabble in this before I discovered re loading the map was easier and cleaner.

I cant reload the map because the player has to go back to the TitleScreen page (map).
What do you think to use this method? :

  • Delete all BO_Actors
  • Unload Map
  • open Level (the desired level)

Create a Actor object reference for a level actor. On Actor spawn set owner (Level Actor). When the level is unloaded all owned actors will be destroyed.

Thanks for the advice, in my case it is a bit complicated this scenario. Let me also speak with my collabs.
At the moment I’ve created a function which read every class that spawn Actors, then store in an array, then delete all actors by class,
what you think about it?

Depends on the number of things in the array that needs to be looped. Small it’s fine. Large, then you might have performance issues.

Next tick cannot start until the loop finishes. Thus Loops increase frame time (decrease FPS).


It shouldn’t be at all complicated.

Level Actor (empty actor class) … placed in the level. Save level.
On spawn, get all actors of class -> get ref (0) -> set spawned actors owner.

The level owns the level actor. The level actor owns the spawned thing. On unload level… everything owned by the level and its actors is destroyed.

This recommendation doesn’t seems to work, i made the test creating a blueprint “spawner” that spawns other blueprints defining itself as the owner, this “spawner” was placed in one of my stream levels and when i unload the level the spawned objects remain in the viewport