[英]How to edit AssetRegistry tags with function?
對於工作流(以及學習目的),我嘗試創建一個 function 以便我們可以將 AssetRegistry 標簽添加到內容瀏覽器中的現有靜態網格對象(來自 EditorUtilityWidget 或任何藍圖),因此能夠通過這些標簽對其進行排序,無需 go 通過上下文菜單“資產操作”->“顯示元數據”來查看它們(正如我們可以使用編輯器腳本實用程序插件中的“設置元數據標記”-節點)。
ExpBlueprintFunctionLibrary.h
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "ExpBlueprintFunctionLibrary.generated.h"
UCLASS()
class DP_API UExpBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "")
static void AddCustomTag(UObject* Asset);
};
ExpBlueprintFunctionLibrary.cpp
#include "AssetRegistry/IAssetRegistry.h"
#include "ExpBlueprintFunctionLibrary.h"
void UExpBlueprintFunctionLibrary::AddCustomTag(UObject* Asset)
{
int32 NewParam = 454;
static TArray<FAssetRegistryTag> AssetTags;
Asset->UObject::GetAssetRegistryTags(AssetTags);
AssetTags.Add(FAssetRegistryTag(
"ExtraTag",
FString::FromInt(NewParam),
FAssetRegistryTag::ETagType::TT_Numerical));
for (const FAssetRegistryTag& AssetTag : AssetTags)
{
UE_LOG(LogTemp, Log, TEXT("Tag : %s :: %s"), *AssetTag.Name.ToString(), *AssetTag.Value)
}
//Super::GetAssetRegistryTags(AssetTags);
}
我要添加到AssetRegistryTagsScreenshot的標簽列表
上面的代碼實際上添加了標簽,但它不在列表中,也沒有過濾器搜索
輸出日志:
LogTemp: Tag : Triangles :: 48
LogTemp: Tag : Vertices :: 54
LogTemp: Tag : UVChannels :: 2
LogTemp: Tag : Materials :: 1
LogTemp: Tag : ApproxSize :: 100x100x100
LogTemp: Tag : CollisionPrims :: 1
LogTemp: Tag : LODs :: 1
LogTemp: Tag : MinLOD :: 0
LogTemp: Tag : SectionsWithCollision :: 1
LogTemp: Tag : DefaultCollision :: BlockAll
LogTemp: Tag : CollisionComplexity :: CTF_UseSimpleAndComplex
LogTemp: Tag : AssetImportData :: []
LogTemp: Tag : LODGroup :: None
LogTemp: Tag : NeverStream :: False
LogTemp: Tag : ExtraTag :: 454
我有一種感覺,我必須以某種方式注冊它並且不太明白我想念什么。
我在藍圖BlueprintScreenshot中連接它的方式
通過我能找到的一小部分示例,我們設法創建了一個自定義 Class-objects 並覆蓋GetAssetRegistryTags
,但它不適用於現有的 StaticMeshes 實例:
。H
...
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, AssetRegistrySearchable, Category = Max)
int32 MaxCount;
int32 DummyData;
.cpp
void UExpBlueprintFunctionLibrary::GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const
{
Super::GetAssetRegistryTags(OutTags);
OutTags.Add(FAssetRegistryTag(
"DummyData",
FString::FromInt(DummyData),
FAssetRegistryTag::ETagType::TT_Numerical
));
}
(非常感謝 Alex Stevens( @MilkyEngineer )在他的推文中的解釋)
這可能是我試圖實現的目標嗎?
PS:歡迎任何確切和概念性的解釋,這將非常有幫助! 我已經花了很多時間試圖弄清楚它應該如何工作並且現在感覺有點絕望和無用
您的代碼不會在您傳入的UObject
上添加標簽,它只是將標簽添加到您的 static 函數本地AssetTags
數組。
我看到不需要覆蓋UObject::GetAssetRegistryTags
的唯一方法是綁定到 static OnGetExtraObjectTags
委托並在回調中添加標簽。 這將要求您保留自己的數據結構,哪些標簽應該添加到哪個 object。
In other words, your call to AddCustomTag
would add a tag on some static or singleton map that keeps an array of extra tags for each object, eg
TMap<UObject*, TArray<FAssetRegistryTag>> ExtraTags;
void UExpBlueprintFunctionLibrary::AddCustomTag(UObject* Asset)
{
int32 NewParam = 454;
ExtraTags.FindOrAdd(Asset).Add(FAssetRegistryTag(
"ExtraTag",
FString::FromInt(NewParam),
FAssetRegistryTag::ETagType::TT_Numerical));
}
在回調中,您將檢查傳入的 object 是否應該收到任何額外的標簽:
void UExpBlueprintFunctionLibrary::ModifyTags(const UObject* Obj, TArray<FAssetRegistryTag>& InOutTags)
{
if (const TArray<FAssetRegistryTag>* pTags = ExtraTags.Find(Obj))
{
InOutTags.Append(*pTags);
}
}
請記住,在您保存資產之前,實際上不會添加標簽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.