Knowledge Base: Adding New Asset Types

Article written by Alex K.
It’s not uncommon for you to have some custom data for your project that you need to edit, store, and associate with different objects. Rather than represent this data as an existing asset typ…

https://dev.epicgames.com/community/learning/knowledge-base/q545/unreal-engine-adding-new-asset-types

4 Likes

Thank you, this helps! Could you give me a hint how to display the user a message if he drags in a file which is already impotred to ask him if he wants to overwrite the file?

You could start by checking this docs page out and seeing if there’s a hint for you in there. Beyond that, I would ask over in the Editor Scripting forum.

1 Like

Didn’t work. I have this class that I’d like to create assets from:

class MYGAME_API UMyPlayerState : public UObject
{
	GENERATED_BODY()

public:
	/** Flipbook currently being played */
	UPROPERTY(Category = Sprite, EditAnywhere, meta = (DisplayThumbnail = "true"))
	UPaperFlipbook* SourceFlipbook;
};

Then I create the factory:

UCLASS()
class MYGAME_API UMyPlayerStateFactory : public UFactory
{
	GENERATED_BODY()
public:
	UMyPlayerState(const FObjectInitializer& ObjectInitializer);

	virtual UObject* FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) override;
	virtual bool ShouldShowInNewMenu() const override;
};

UMyPlayerStateFactory::UMyPlayerStateFactory(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer) {
	bCreateNew = true;
	bEditAfterNew = true;
	SupportedClass = UMyPlayerState::StaticClass();
}

UObject* UMyPlayerStateFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) {
	UMyPlayerState* NewSprite = NewObject<UMyPlayerState>(InParent, Class, Name, Flags | RF_Transactional);

	return NewSprite;
}

bool UMyPlayerStateFactory::ShouldShowInNewMenu() const {
	return true;
}

Then when I right click in the editor(I compiled the project inside Visual Studio and then restarted the editor), I only get the default classes that are available by default:

Managed to fix my problem by creating the FAssetTypeActions class and then registering in the module’s StartupModule function. But at the start of this section at the moment of writing this paragraph we can’t yet import an asset or create new asset in the editor.

Also, the guide is missing on where to find and how to add the code to the StartupModule function.

I managed to find the guide on how to do that here: Quick C++ Tip - Overriding your game's StartupModule / ShutdownModule functions.

Still, when you’re making a guide/tutorial, users should be able to just follow the steps even when they are experiencing it for the first time, and this guide is missing quite a lot of info that I, by chance, either already knew or managed to guess and research successfully. But what if there was no this other guide for overriding game’s startup module? I’d have to create a thread for it. But then there are other 10 things that’s missing from the guide. What if I already didn’t know it and/or couldn’t do them successfully? Create 10 threads total and spend 2 weeks on this?