[Tutorial] UE5 How to create a custom asset type

This tutorial will cover creating a custom asset that will appear and be used in the unreal engine editor. There are two scenarios in which a custom asset may be made. Your goal might be to create an asset from reading a file in some other extension that unreal engine does not recognize. Or, You may like to create the asset by right-clicking in the editor and creating a new asset. 

How to import unsupported or new file extensions in unreal engine

We will begin by showing you how to import unsupported file extensions into unreal engine as custom assets. This means you will be able to select a file with some extension and unreal engine will be able to read it and create a new uasset from it.

1. Create Child Class From UObject

Create a class that inherits from UObject. The purpose of this class is to hold the data that gets read in from the new file. For example, lets pretend we had a file extension .bcg and we would like to read in data from these type of files. Our UObject could be named UBcgAsset. 

TIP: Inside this object, you may want to store the original file’s path for later use. For example, if you would like to enable reimport functionality for your custom asset type you will need this file path. You can follow this link to add reimport support to your custom asset type.

				
					#if WITH_EDITORONLY_DATA
UPROPERTY(VisibleAnywhere)
FString SourceBCGFile;
#endif
				
			

WITH_EDITORONLY_DATA instructs unreal engine to compile and store this data only for Editor environments. That is, this data/variables will be stripped out and will not exist in shipping builds.

2. Create a Child Class From UFactory

UFactory is the class responsible for reading and creating files. It’s a UAsset creator or file creator. Hence the name; Factory. A factory makes / manufactures things and that’s what the UFactory class is for.

We create a new class that inherits from UFactory and then override a few functions. FactoryCreateFile() is the function you want.

				
					virtual UObject* FactoryCreateFile(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, const FString& Filename, const TCHAR* Parms, FFeedbackContext* Warn, bool& bOutOperationCanceled) override;
				
			

One other critical step is instructing the unreal editor to read in the new file extension. We do this in the Constructor or our UFactory child class and the way to do it is to call the
Formats->Add(“extension;description”) function. Formats is a variable inherited from Ufactory. Example:

Lets say we want to read and import files with “.bcg” file extension. This is how you instruct unreal engine to support the .bcg file.

				
					UBcgAssetFactory::UBcgAssetFactory()
{
	Formats.Add("bcg;BCG File");
	SupportedClass = UBcgAsset::StaticClass();
	bCreateNew = false;
	bEditorImport = true;
}
				
			

Once we read the file, SupportedClass is the class we’d like to create an object from. Remember, this is a minified tutorial. The best way to learn this is by taking our plugin development course. Videos are the best way to cover this topic and that’s where we cover everything from A-Z.

3. Return a UObject inside FactoryCreateFile()

Inside the implementation of the FactoryCreateFile() override, you need to do one critical thing:

 

You need to create a UObject (or child class of UObject) and return this UObject. This is where the class we created in step 1 comes in. You need to create the object with NewObject and then modify the object before returning it.

 

In our case, modifying the object means we read data from our new file extension and then convert and store that data into our UBcgAsset child class object and then we return this object.

 

You should be able to select BCG files when you use the import button in the editor and unreal engine will do the rest. Your asset should appear in the editor shortly after.

 

You do not need to worry about instantiating this UFactory as unreal engine will automatically scan and instantiate all UFactory child classes.

Conclusion

These 3 main steps are the critical steps needed to create a new asset in unreal engine. If you want to create the new UAsset  from right-click, you just need to set bCreateNew=true; 
We highly recommend looking at other plugin source files or taking our unreal engine plugin development course. Whichever you’re comfortable with. This tutorial is around 60% of the explanation but you at least have an idea of the path to follow and the critical classes needed to accomplish the task of creating custom assets in unreal engine.

You can always contact us by email for free support and let us know how we are doing.

5/5

Gamechanger plugin for notehighway rhythm games and music visualizers

5/5

Add Text and 2D UMG widgets to Level Sequences

Consider investing in some of our plugins. They might save you some time.  Also helps supports these tutorials.

Instantly get access to our plugins like Blender Curves Importer and UMG Cinematics and more when  you support us on Patreon!

 Join Us On Discord For More Daily Tips!