How can I load/unload a sublevel(tile) in a world composition?

I want to load/unload tiles in a world composition called from a blutility function in editor mode (not ingame). In the picture below you can see the contextmenu for load/unload tiles. I want the same functionality via a blueprint function.

I tested UGameplayStatics::LoadStreamLevel / UGameplayStatics::UnloadStreamLevel in BlueprintFunctionLibrary in a sample project.

void UMyBlueprintFunctionLibrary::LoadLevel(FName LevelName)
{
	FLatentActionInfo info;
	info.CallbackTarget = 0;
	info.ExecutionFunction = FName("");
	info.Linkage = 0;
	info.UUID = 0;

	UGameplayStatics::LoadStreamLevel(GWorld->GetWorld(), LevelName, true, false, info);
}

void UMyBlueprintFunctionLibrary::LoadLevelEditor(FName LevelName)
{
	FLatentActionInfo info;
	info.CallbackTarget = 0;
	info.ExecutionFunction = FName("");
	info.Linkage = 0;
	info.UUID = 0;

	UGameplayStatics::LoadStreamLevel(GEditor->GetEditorWorldContext().World(), LevelName, true, false, info);
}

“LoadLevel” does work ingame but not in editor mode called from a blutility function.

“LoadLevelEditor” does not work at all and gives the error “LogLevel: Warning: Failed to find streaming level object associated with ‘sub1’”

Is there any way to achieve the same result as clicking Load/Unload in the contextmenu?

You will need to look at using the functions:

UGameplayStatics::LoadStreamLevel
UGameplayStatics::UnloadStreamLevel

If you are using them in C++, you may also need to add the header:
#include “Kismet/GameplayStatics.h”

I tried it and edited my question

UGameplayStatics class is meant for runtime code.
If you’d like to manage levels in the editor, you need EditorLevelUtils.

In my implementation, I keep an array of level names in the form of presets, so the user can easily switch between level presets. Then I retrieve ULevelStreaming* from the world (method in custom World Settings) and pass it to EditorLevelUtils methods.

This is ready snipper for you :slight_smile:

https://gist.github.com/DoctorErgot/c98aa7fcb7ef7548338e24d950b8667c

1 Like

I know this is super late, but I was also looking into this, for another reason by means of a c++ plugin.
And I found you can do it using the following.

You need to add the “WorldBrowser” module.

I know this is super late, but I was also looking for this in c++ via plugin for another reason, and finally managed to get it working, so answering here for prosperity.

You need to include “WorldBrowser” module.
And the following headers:

#include "WorldBrowserModule.h"
#include "Engine/WorldComposition.h"
#include "WorldBrowser/Private/LevelCollectionModel.h"

Then get a handle to the world browser module, shared world model, and manipulate the levels from there.

FWorldBrowserModule& WorldBrowserModule = FModuleManager::GetModuleChecked<FWorldBrowserModule>("WorldBrowser");
TSharedPtr<FLevelCollectionModel> SharedWorldModel = WorldBrowserModule.SharedWorldModel(world);

const FLevelModelList& modelLevels = SharedWorldModel->GetAllLevels();
SharedWorldModel->LoadLevels(modelLevels);

In a nutshell simply use the “FWorldBrowserModule.SharedWorldModel.LoadLevels” and pass it a list ( can also only contain one level if you like )

3 Likes

You should then be able to expose this to blueprint as static functions or example. I can not find any existing pre exposed blueprint functionality other than a lot of custom slate widgets *( the world composition widgets as it happens, uses this same method to load/unload levels )