How to properly unstream and remove a ULevelStreaming from the world?

For example, once you stream in a level like so :

 ULevelStreamingKismet* StreamingLevel = NewObject<ULevelStreamingKismet>((UObject*)GetTransientPackage(), ULevelStreamingKismet::StaticClass());
 
// more stuff 

 StreamingLevel->bShouldBeLoaded = true;
 StreamingLevel->bShouldBeVisible = true;
 
// more stuff

 World->StreamingLevels.Add(StreamingLevel);

And then you decide to unstream it by changing the visible and loaded booleans:

 StreamingLevel->bShouldBeLoaded = false;
 StreamingLevel->bShouldBeVisible = false;

But that doesn’t entirely remove it from memory and the world because you still have a pointer to the ULevelStreaming and can reassign those booleans to true and the level will stream back in the world again.

So how would you remove it completely from the world? Do you make sure you delete the only pointer you have as a reference to it after you set those booleans to false? Will that completely remove it from memory?

I ask because I’m going to stream in a lot of levels in and out and I don’t want to have levels dangling around that I don’t need.

me too ,take care of this !

I have yet to test this but ULevelStreaming::SetIsRequestingUnloadAndRemoval sounds like it would do the job. Currently I’m doing this by getting the loaded level with ULevelStreaming::GetLoadedLevel and then calling UEditorLevelUtils::RemoveLevelFromWorld() but this obviously won’t remove unloaded streaming levels. (Which is what ULevelStreaming::SetIsRequestingUnloadAndRemoval hopefully does)