Creating a Custom Editor Asset in Unreal Engine 4

This guide will provide you with a step-by-step explanation on how to set up your own custom asset. We will add some properties and make sure the asset can be spawned through Unreal its Editor interface. This guide will serve as a foundation for your asset from which you can start extending it with your own functionality.

Creating your own custom editor assets can be useful during production as designers might want data assets that can quickly be swapped out to test multiple values in game. Another example could be to provide data for dialogues where the assets represent all the dialogues of a certain character. Being able to quickly access and edit data can prove extremely useful during production.

About you

This guide is for Unreal Engine C++ programmers who are interested in exposing assets to the editor. At the end of this guide, you will have learned how to expose your custom assets to the editor and you will be able to modify through the simple asset editor.

In this guide, you will learn how to create a custom asset and how to make it available via the Unreal Editor interface. You will create two C++ classes named MyCustomAsset and MyCustomAssetFactory to achieve this functionality. During this guide, I will provide some information about what these specific classes are used for.

You are expected to have some experience with programming C++ in Unreal Engine 4. You are familiar with the editor and have a basic understanding of how to create classes through Unreals Editor interface.

What will you learn

In this guide, you will learn how to create a custom asset and how to make it available through Unreal Editor interface. We will start by creating the MyCustomAsset class which will be the object that we want to expose to the editor. We will continue by creating the MyCustomAssetFactory and make the asset available via the editor.

During this guide, I will provide information about what these specific classes are used for and I will provide links to Unreal's technical API for more information about the classes.

Prerequisites

Additional Notes

This guide is mainly written as a set-up for a more comprehensive guide that explains how to create and implement a Custom Asset Editor for Unreal Engine 4. If you are interesting in achieving this, you might want to start at the beginning.

Creating our Custom Asset



We create a class called MyCustomAsset which inherits from Object. This class will represent our asset and can be referenced in code or blueprints.
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "MyCustomAsset.generated.h"

/**
 * 
 */
UCLASS()
class ASSETEDITORTUTORIAL_API UMyCustomAsset : public UObject
{
	GENERATED_BODY()
	
protected:
	UPROPERTY(VisibleAnywhere, Category = MyCustomAsset)
	FString Description;

	UPROPERTY(VisibleAnywhere, Category = MyCustomAsset)
	bool bIsActive;
};

In the header file, we add some properties that will be displayed in the editor.

Creating the Custom Asset Factory



We create a class called MyCustomAssetFactory which inherits from Factory. This will be the base class responsible for creating and importing new Custom Asset objects and will allow us to construct the asset through the editor interface.

Setting up the header file

#include "CoreMinimal.h"
#include "Factories/Factory.h"
#include "MyCustomAssetFactory.generated.h"

/**
 * 
 */
UCLASS()
class ASSETEDITORTUTORIAL_API UMyCustomAssetFactory : public UFactory
{
	GENERATED_BODY()

public:
	UMyCustomAssetFactory();

	// Begin UFactory Interface
	virtual UObject* FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) override;
	// End UFactory Interface
};

We begin by implementing the FactoryCreateNew function from the UFactory interface. This function is called whenever we want a new object to be constructed and we will set it up to spawn an MyCustomAsset object in our implementation file.

Setting up the implementation

#include "MyCustomAssetFactory.h"
#include "MyCustomAsset.h"

UMyCustomAssetFactory::UMyCustomAssetFactory()
{
	// Provide the factory with information about how to handle our asset
	bCreateNew = true;
	bEditAfterNew = true;
	SupportedClass = UMyCustomAsset::StaticClass();
}

UObject* UMyCustomAssetFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
	// Create and return a new instance of our MyCustomAsset object
	UMyCustomAsset* MyCustomAsset = NewObject<UMyCustomAsset>(InParent, Class, Name, Flags);
	return MyCustomAsset;
}

In our implementation, we will provide our factory with some additional properties. We set bCreateNew to true as we want this factory to be able to construct new objects. Since we also want the associated editor to open automatically after creating the object, we also flag bEditAfterNew to true. Finally, we need to tell the factory which class to manufacture so we add our Custom Asset as the SupportedClass.

In the FactoryCreateNew function, we create and return a new Custom Asset object. This is everything we need to do to be able to create our MyCustomAsset in the Unreal Editor. We can now recompile our code and start the editor.

Testing the Custom Asset Editor in Unreal

After the editor has started you can right-click the content browser and navigate to the "Miscellaneous" section where you can find our asset. Clicking it will create a new instance of our asset in the content browser.

Conclusion

You have learned how to create a custom asset that can be spawned via the Unreal Editor interface. You have learned that an asset object is represented as a UObject and that it can be spawned through the editor if we provide a UFactory implementation for it.

If you have any questions or comments on this guide, feel free to email me at cairan.steverink@gmail.com and I will be happy to answer your questions.

Further Reading and References


Share this Post: