How to dynamically load umaps (C++)

[Creating a umap and loading it on the fly seems to be a good way to manage loading and unloading collections of objects]

It took me a while messing around with this to get it, many of the instructions out there seem a considerably more complicated than I was after so I thought I’d post the skinny version I ended up with. This isn’t a question - hopefully a shortcut for someone trying to do what I’ve been trying to do.

If you don’t have a levels view open one from under the “windows” main menu option.

If you’ve already created a level the Levels dropdown option allows you to add an existing item, otherwise it also allows you to create a new one.

The left hand column allows you to show and hide the objects in the editor.

In C++:

ULevelStreaming *pStreaming = UGameplayStatics::GetStreamingLevel(pWorld, FName(*LevelName));
if (pStreaming)
{
	pStreaming->bShouldBeLoaded = true;
	pStreaming->bShouldBeVisible = true;
}

And hey presto it will load.

Want to unload it? Guess what…

ULevelStreaming *pStreaming = UGameplayStatics::GetStreamingLevel(pWorld, FName(*LevelName));
if (pStreaming)
{
	pStreaming->bShouldBeLoaded = false;
	pStreaming->bShouldBeVisible = false;
}

There are probably a thousand edge cases for this and things that can go wrong but the above was enough to get me rolling. Here are a couple of little gotchas though:

  • Visibility in the editor is left in the state you leave it in. I haven’t yet found the right place to restore this post PIE.
  • Remembering to launch the game from the right level. If you are editing a sublevel that is a dumb object container and press play you may not get the gameplay experience you expect.

Otherwise it seems like lots of cool stuff just works out of the box, lighting, blueprints, etc! You can get the ULevel via the streaming object, do tests too see if things are loaded etc.

The question is an answer!

hi,
is it possible to create a new blank level(umap) and add it with persistent level as a streaming level?