Is it possible to add custom asset category for custom Data Asset?

Yes, it´s possible for any UObject; you just have to create an asset factory for your custom class:

In runtime module:



#include "Runtime/Engine/Classes/Engine/DataAsset.h"

USTRUCT()
struct FMyItemInfo{

    GENERATED_USTRUCT_BODY()

    UPROPERTY(EditAnywhere)
    FString itemName;

    UPROPERTY(EditAnywhere)
    UTexture2D* itemThumbnail;

    UPROPERTY(EditAnywhere)
    UBlueprint* itemBlueprint;

    UPROPERTY(EditAnywhere)
    FColor itemColor;
};

UCLASS(ClassGroup = Synaptech, Category = "Synaptech", BlueprintType, Blueprintable)
class USQLITE_API UMyItemsDatabase : public UDataAsset
{
    GENERATED_BODY()

    UPROPERTY(EditAnywhere)
    TArray<FMyItemInfo> items;

};


In Editor module:



static EAssetTypeCategories::Type MY_AssetCategory;


UCLASS()
class UMYEDITOR_API UMyItemsDatabase_Factory : public UFactory {
    GENERATED_UCLASS_BODY()
protected:
    virtual bool IsMacroFactory() const { return false; }
public:
    virtual UObject* FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) override;
};


.H:



class FATA_UMyItemsDatabase : public FAssetTypeActions_Base {
public:
    virtual FText GetName() const override { return LOCTEXT("MyDataAsset","My Items Data Asset"); }
    virtual uint32 GetCategories() override { return MY_AssetCategory; }
    virtual FColor GetTypeColor() const override { return FColor(127,255,255); }
    virtual FText GetAssetDescription(const FAssetData &AssetData) const override { return LOCTEXT("MyDataAssetDesc","My DataAsset description."); }
    virtual UClass* GetSupportedClass() const override { return UMyItemsDatabase::StaticClass(); }
};


.CPP:



UMyItemsDatabase_Factory::UMyItemsDatabase_Factory(const class FObjectInitializer &OBJ) : Super(OBJ) {
    SupportedClass = UMyItemsDatabase::StaticClass();
    bEditAfterNew = true;
    bCreateNew = true;
}

UObject* UMyItemsDatabase_Factory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
    check(Class->IsChildOf(UMyItemsDatabase::StaticClass()));
    return NewObject<UMyItemsDatabase>(InParent,Class,Name,Flags|RF_Transactional,Context);
}


Then the key step you have to take is within your Editor Module’s StartupModule() function:



StartupModule() {
    IAssetTools &AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
    MY_AssetCategory = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("MyCustomCategory")),LOCTEXT("MyCustomCategory","MyCustomCategory"));
    {
        TSharedRef<IAssetTypeActions> ACT_UMyItemsDatabase = MakeShareable(new FATA_UMyItemsDatabase);
        AssetTools.RegisterAssetTypeActions(ACT_UMyItemsDatabase);
    }
}


6 Likes