Some interesting ideas there, thanks for the suggestions!
But actually I don’t care about packaged game, I just wanted to use this to clean up World Outliner while working in editor (put each actor to subfolder with name of the sublevel that actor is stored in).
So following the example from previous message result should look like this.
And this is actually a result of a working script.
So in case anyone stumbles upon this thread in future - here’s how I did it.
Added WorldBrowser to PrivateDependencyModuleNames in my MyProjectEditor.Build.cs
PrivateDependencyModuleNames.AddRange(new string[] { "WorldBrowser" });
Then in one of BPL classes
// Necessary includes
#include "WorldBrowserModule.h"
#include "Engine/WorldComposition.h"
#include "WorldBrowser/Private/LevelCollectionModel.h"
...
// Getting model which contains list of all SubLevels
FWorldBrowserModule& WorldBrowserModule = FModuleManager::GetModuleChecked<FWorldBrowserModule>("WorldBrowser");
TSharedPtr<FLevelCollectionModel> SharedWorldModel = WorldBrowserModule.SharedWorldModel(WorldContextObject->GetWorld());
...
// Now iterating by all SubLevels
for (TSharedPtr<FLevelModel> Child : SharedWorldModel->GetAllLevels())
{
if (Child.Get()->GetDisplayName() == "Persistent Level")
{
// Will return the name of the level - HierarchyTest from the example above
FString LevelName = WorldContextObject->GetWorld()->GetMapName();
}
else
{
// Will return HierarchyTest_Sublevel1 from the example above
FString SubLevelName = Child.Get()->GetDisplayName();
// Will return SubFolder1 from the example above
FName SubLevelPath = Child.Get()->GetFolderPath();
}
}
Now this is quite hacky way since it uses Private stuff of WorldBrowser, but it works well.
Thanks to these topics: