简体   繁体   English

如何使用 function 编辑 AssetRegistry 标签?

[英]How to edit AssetRegistry tags with function?

For a workflow (and for the learning purposes as well) i try to create a function so we can add AssetRegistry tags to the existing StaticMesh objects in Content Browser (from a EditorUtilityWidget or any blueprint) and therefore to be able sort it by these tags, without necessity to go through context menus "Asset Actions"->"Show Metadata" to see them(as we can do with "Set Metadata Tag"-Node from Editor Scripting Utilities plugin).对于工作流(以及学习目的),我尝试创建一个 function 以便我们可以将 AssetRegistry 标签添加到内容浏览器中的现有静态网格对象(来自 EditorUtilityWidget 或任何蓝图),因此能够通过这些标签对其进行排序,无需 go 通过上下文菜单“资产操作”->“显示元数据”来查看它们(正如我们可以使用编辑器脚本实用程序插件中的“设置元数据标记”-节点)。

ExpBlueprintFunctionLibrary.h 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 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);
}

the tags list that i mean to add to AssetRegistryTagsScreenshot我要添加到AssetRegistryTagsScreenshot的标签列表

the code above actually adds tag to it, but it is not in the list nor filter to search上面的代码实际上添加了标签,但它不在列表中,也没有过滤器搜索

OutputLog:输出日志:

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

i have a feeling that i have to somehow register it and didn't quite understand what i miss.我有一种感觉,我必须以某种方式注册它并且不太明白我想念什么。

the way i connect it in blueprint BlueprintScreenshot我在蓝图BlueprintScreenshot中连接它的方式

with small portions of examples i could find, we managed to create a custom Class-objects and override GetAssetRegistryTags , but it doesn't work for existing instances of StaticMeshes:通过我能找到的一小部分示例,我们设法创建了一个自定义 Class-objects 并覆盖GetAssetRegistryTags ,但它不适用于现有的 StaticMeshes 实例:

.h 。H

...
public:
        UPROPERTY(EditAnywhere, BlueprintReadOnly, AssetRegistrySearchable, Category = Max)
        int32 MaxCount;
    
        int32 DummyData;

.cpp .cpp

void UExpBlueprintFunctionLibrary::GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const
{
    Super::GetAssetRegistryTags(OutTags);

    OutTags.Add(FAssetRegistryTag(
        "DummyData",
        FString::FromInt(DummyData),
        FAssetRegistryTag::ETagType::TT_Numerical
    ));
}

(here are really huge thanks for explanations Alex Stevens (@MilkyEngineer) in his tweetorial ) (非常感谢 Alex Stevens( @MilkyEngineer )在他的推文中的解释)

Is that possible what i try to achieve?这可能是我试图实现的目标吗?

PS: any exact and conceptual explanations are welcome and would be greatly helpful! PS:欢迎任何确切和概念性的解释,这将非常有帮助! i've already spent a lot of time trying to figure out how should it work and feel a little bit desperate and useless right now我已经花了很多时间试图弄清楚它应该如何工作并且现在感觉有点绝望和无用

Your code doesn't add a tag on the UObject you are passing in, it just adds a tag to your static function-local AssetTags array.您的代码不会在您传入的UObject上添加标签,它只是将标签添加到您的 static 函数本地AssetTags数组。

The only way I see that doesn't require overriding UObject::GetAssetRegistryTags is to bind to the static OnGetExtraObjectTags delegate and add the tags in the callback.我看到不需要覆盖UObject::GetAssetRegistryTags的唯一方法是绑定到 static OnGetExtraObjectTags委托并在回调中添加标签。 This would require you to keep your own data structure of which tags should be added to which object.这将要求您保留自己的数据结构,哪些标签应该添加到哪个 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 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));
}

In the callback you would check if the object passed in should receive any extra tags:在回调中,您将检查传入的 object 是否应该收到任何额外的标签:

void UExpBlueprintFunctionLibrary::ModifyTags(const UObject* Obj, TArray<FAssetRegistryTag>& InOutTags)
{
    if (const TArray<FAssetRegistryTag>* pTags = ExtraTags.Find(Obj))
    {
        InOutTags.Append(*pTags);
    }
}

Keep in mind the tags won't actually be added until you save the asset.请记住,在您保存资产之前,实际上不会添加标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM