<aside> ⚙
Unreal Engine 5.4
</aside>
<aside> ⚠️
In older versions this was handled differently
</aside>
Add a new Unreal Module to your Plugin.

Change the Module Type to Editor and Loding Phase to PostEngineInit

The following module loading code needs to be in the plugins .uplugin file.
"Modules": [
{
"Name": "PluginName",
"Type": "Runtime",
"LoadingPhase": "Default"
},
{
"Name": "ModuleName",
"Type": "Editor",
"LoadingPhase": "PostEngineInit"
}
],
First we need to create an AssetDefinition that tells the engine how the asset should be styled.
Item.h is the custom asset type.
#pragma once
#include "CoreMinimal.h"
#include "AssetDefinitionDefault.h"
#include "Item.h"
#include "UAssetDefinition_Item.generated.h"
UCLASS()
class CUSTOMEDITORASSETS_API UAssetDefinition_Item : public UAssetDefinitionDefault
{
GENERATED_BODY()
virtual TSoftClassPtr<UObject>GetAssetClass() const override {return UItem::StaticClass();}
virtual FText GetAssetDisplayName() const override {return FText::FromString("Item");}
virtual FLinearColor GetAssetColor() const override {return FLinearColor::Green;}
virtual TConstArrayView<FAssetCategoryPath> GetAssetCategories() const override
{
static const FAssetCategoryPath Categories[] = {FText::FromString("Inventory")};
return Categories;
}
};
Then we need to define a new UFactory that will create the new Asset Type.
#pragma once
#include "CoreMinimal.h"
#include "Factories/Factory.h"
#include "UItemFactory.generated.h"
UCLASS()
class UItemFactory: public UFactory
{
GENERATED_BODY()
UItemFactory(const FObjectInitializer& FObjectInitializer);
virtual UObject* FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) override;
};
#include "UItemFactory.h"
#include "Item.h"
UItemFactory::UItemFactory(const FObjectInitializer& FObjectInitializer):Super(FObjectInitializer)
{
SupportedClass = UItem::StaticClass();
bCreateNew = true;
bEditorImport = false;
bEditAfterNew = true;
}
UObject* UItemFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
return NewObject<UItem>(InParent, Class, Name, Flags | RF_Transactional);
}
Dont forget to add public dependencies in your new module Build.cs
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core", "InventorySystem", "AssetDefinition", "UnrealEd", "AssetRegistry"
}
);
<aside> ⚠️
Different Object creation syntax if you want a BlueprintGraph
</aside>
<aside> ⚠️
If you are using CreateBlueprint asset styling will be overriden by UBlueprint
</aside>
<aside> 💡
If you want custom asset Blueprint styling you need to create a new UBlueprint child
</aside>
return FKismetEditorUtilities::CreateBlueprint(Class, InParent, Name, BPTYPE_Normal, UBlueprint::StaticClass(), UBlueprintGeneratedClass::StaticClass());