介绍

很突然,曾经想要 World Outliner 中的文件夹列表吗?
我有这次,我们将介绍如何获取它。它需要 C++,但可以快速完成。
[UE5] World Outliner上のフォルダのリストを取得する方法について(おまけ付き)

C++ 代码

要获取文件夹,请使用FActorFoldersForEachFolder 函数。它的写法有点陌生,但这是因为它使用了TFunctionRef

MyEditorBlueprintFunctionLibrary.cpp
#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyEditorBlueprintFunctionLibrary.generated.h"

UCLASS()
class ●●●●EDITOR_API UMyEditorBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

	UFUNCTION(BlueprintCallable)
	static TArray<FName> GetActorFolderNames(UWorld* World, bool bUseSort);
};
MyEditorBlueprintFunctionLibrary.h
#include "MyEditorBlueprintFunctionLibrary.h"
#include "EditorActorFolders.h"

TArray<FName> UMyEditorBlueprintFunctionLibrary::GetActorFolderNames(UWorld* World, bool bUseSort)
{
	TArray<FName> OutActorFolderNames;

    // 全フォルダ(FFolder)に対してForEach処理を実行
	FActorFolders::Get().ForEachFolder(*World, [&OutActorFolderNames](const FFolder& Folder)
	{
		OutActorFolderNames.Add(Folder.GetPath());
		return true;
	});
	if(bUseSort)
	{
		OutActorFolderNames.Sort();
	}
	return OutActorFolderNames;
}

另外,由于上述代码使用了仅编辑器的功能,强烈推荐使用Editor模块。有关如何创建编辑器模块,请参阅以下文章,或

我们建议使用这个免费插件。我发现它很有用,因为我可以快速添加模块。

回到主题...
当由此创建的Get Actor Folder Names节点按如下方式组装并执行...
[UE5] World Outliner上のフォルダのリストを取得する方法について(おまけ付き)
结果如下所示:你答对了!

LogBlueprintUserMessages: [XXX] A
LogBlueprintUserMessages: [XXX] B
LogBlueprintUserMessages: [XXX] B/B-Child
LogBlueprintUserMessages: [XXX] C

应用示例

如果只是这个就很微妙了,所以让我们谈谈它具体有什么用......

首先,您可以使用 Actor 的 SetFolderPath 节点将 Actor 移动到特定文件夹。这里的文件夹自然是指World Outliner中的文件夹。而如果把SetFolderPath节点和本次介绍的内容结合起来……如果找到特定文件夹名称,则将选定的 Actor 移动到那里您可以设置该过程。
[UE5] World Outliner上のフォルダのリストを取得する方法について(おまけ付き)

仅此一项并没有什么特别的用途,标准的 Move To 功能就可以了!但

例如…

  • 根据特定规则将多个 Actor 批量移动/组织到文件夹
  • 当您在关卡上放置特定的 Actor/BP 时,它会自动移动到相应的文件夹

您可以构建一个编辑器扩展,例如你怎么看?方便,不是吗?

最后

随着开发规模的扩大,World Outliner 上的 Actor 数量趋于膨胀。而且,如果你使用UE5的World Partition,它可能会膨胀到UE4时代无法比拟的程度。在这种情况下,这篇文章一定会对你有所帮助。请尝试一次!

结尾


原创声明:本文系作者授权爱码网发表,未经许可,不得转载;

原文地址:https://www.likecs.com/show-308626618.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
相关资源
相似解决方案