I can't seem to unload my instanced sub-levels

Hey guys, first time poster and Blueprint noob here.

I’ve been trying to unload specific Sub-Level instances which I spawned, I’ve tried numerous things, but can’t seem to get it to work properly. I figure it got something to do with my references? But since I’m as much a beginner as I can be, I’m not able to recognize what I’m doing wrong.

What I Want

I’ve got a sidescroller level with two segments, both levels (set as sublevels of a persistant map). An initial script in the persistant level spawns Segment_1, after that I managed to spawn Segment_2, (once the player walks through a triggerbox). The issue comes up when I enter a triggerbox in Segment_2. It should delete the lastest instance of Segment_1 , and spawn a new instance of that segment after itself - in short, creating a level that loops infinitely, almost like an endless runner.

My Problem

The spawning works perfectly, and I can keep running forever. But the game doesn’t unload the previous instances of that level.

Check the screenshots below. When I spawn an instance, I set its name in a variable in another actor (called " BP_segman" - for segment manager-). Before spawning a new instance, I ask a reference of the old one and aks to unload it. But it doesn’t work. If I enter the level name manually in the Unload node, it unloads only the initial instance. So I’m pretty sure my issue is with passing and saving the correct reference.

Can any of you help me / spot my error?

Thanks a million for any help!

Note: I don’t know anything about C++

Segment Blueprint

Segment Manager Blueprint

180157-segment_manager.png

Sidenote: in this example it’s just 2 segments, but in the final levels, the number of segments can be way higher and I intend on unloading the ones that are not adjacent to the segment you’re currently in.

Instead of using create Instance level, use Create Instance. This is an old Kismet function left inside the engine from UDK3.

target is streaming level, give it a unique name ( like appending a random integer to the level name. When you set should be loaded and should be visible to true, it will load on the level, and unload if you set them false.

Important thing is, this node won’t be visible unless you turn of context-sensitive on bp node search.

Also, this note will always give a warning since it is so outdated but it was still working on 4.21 with no problem. Remember that because of that warning bp nativization may or may now work, I never tested it with this node.