BlueprintFunctionLibrary
.h file
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Get Selected Folder", Keywords = "GetSelectedFolder"), Category = "Editor")
static void GetSelectedFolder();
.CPP file
void UBPLibrary::GetSelectedFolder()
{
const TWeakPtr<ILevelEditor> LevelEditor = FModuleManager::GetModuleChecked<FLevelEditorModule>(TEXT("LevelEditor")).GetLevelEditorInstance();
const TSharedPtr<ISceneOutliner> SceneOutlinerInterface = LevelEditor.Pin()->GetMostRecentlyUsedSceneOutliner();
const STreeView<FSceneOutlinerTreeItemPtr>& CurrentTree = SceneOutlinerInterface->GetTree();
TArray<FSceneOutlinerTreeItemPtr> SelectedItems = CurrentTree.GetSelectedItems();
for (const FSceneOutlinerTreeItemPtr SceneOutlinerTreeItem : SelectedItems)
{
if (const FActorFolderTreeItem* FolderItem = SceneOutlinerTreeItem->CastTo<FActorFolderTreeItem>())
{
UE_LOG(LogTemp, Display, TEXT("GetSelectedFolder::SelectedObject %s"),*FolderItem->GetActorFolder()->GetLabel());
UE_LOG(LogTemp, Display, TEXT("GetSelectedFolder::SelectedObject %s"),*FolderItem->GetActorFolder()->GetPath().ToString());
}
}
}
need Dependency Module
"UnrealEd"
"SceneOutliner"