0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

UE5 C++ GetSelectedFolder

Posted at

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"

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?