UE4.25 FactoryCreateNew don't work

In the UE4.24, I can create my own asset by the following code:

TextAsset.h

#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "TextAsset.generated.h"

UCLASS()
class MYPROJECT_API UTextAsset : public UObject
{
	GENERATED_BODY()
	
public:
	UPROPERTY(EditAnywhere)
	FString myString;
};

TextAssetFactory.h

#pragma once
#include "CoreMinimal.h"
#include "Factories/Factory.h"
#include "TextAssetFactory.generated.h"

UCLASS()
class MYPROJECT_API UTextAssetFactory : public UFactory
{
	GENERATED_BODY()
public:
	UTextAssetFactory();

	virtual UObject* FactoryCreateNew(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)override;

	
};

TextAssetFactory.cpp

#include "TextAssetFactory.h"
#include "TextAsset.h"

UTextAssetFactory::UTextAssetFactory() :Super()
{
	bCreateNew = true;
	bEditAfterNew = true;
	SupportedClass = UTextAsset::StaticClass();
}

UObject* UTextAssetFactory::FactoryCreateNew(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
	auto MyTextAsset = NewObject<UTextAsset>(InParent, InClass, InName, Flags);
	return MyTextAsset;
}

this works well in UE4.24

but in UE4.25,using the same code, the new asset don’t show up in the editor

I want to know that there is something changed in UE4.25? Or just bug in UE4.25?

I am confused by this for two days,and can’t find the solution.

thanks in advance for your help!

According to the latest Github, nothing changed for that since 4.24 Github

Are you sure the module is successfully loaded when the engine starts?

Ok, you are right something changed from 4.24.

As far as I can tell, registering of Custom Asset type was always intended to be implemented in a module.

There were few things that you need to change compared to your original approach, but don’t worry, I got you covered. I made you a working demo here.

Changes -

  1. I have created a blank module and moved your code there.
  2. You need to add UCLASS(BlueprintType) to your UTextAsset, otherwise it will not be able to create a Blueprint out of it
  3. Created FTextAssetTypeActions. This file is specifying stuff like name of the asset, what category it should be in, the color etc.
  4. Registered FTextAssetTypeActions in here

If you want, you can just copy pasted the Plugins folder to your project and it should work.

Good luck!

1 Like

thank you very much. Perfect plugin, it works well.

In addition,I want to know if I have to create these 6 file every time I create a new asset?I am not familiar with plugin but i think if i want to create a plugin like yours,I should create 6 files at least.

Also,I try to just copy your code to my projet without using plugin,and It fails to compile.
If possible,can you tell me how to create new asset without using plugin.

the error list is here,and I found that all errors are concentrated on TestModule.cpp

Yes, you need to create the 3 classes (Blueprintable object class, Asset actions for that object and Factory) for every custom type you are adding.

I am confident it is possible to register custom classes in the game project, but here are reasons why you should not do it.

When it comes game development, you need to figure out what should be in the packaged game and what are just tools to help you create the game. You know that you will be using UTextAsset in your game to hold player details (this is an example). But you will not need UTextAssetFactory nor UTextAssetActions, because they are ONLY used to help you build it in the Engine… Without editor, they are completely useless. So if you look into Paper2D, it has multiple modules, Paper2D Editor and Paper2D (core) being two separate modules. This allows to keep the helper editor code separate and allows to run the module only the in editor. So it does not load when you play in standalone or when you ship your game. On the other hand, Paper2D (core) is loaded everywhere, because it contains only the necessary game objects and data.

There are few other reasons why it is better to divide your project into separate modules. but I am running out of characters.

Hope this helps!

Thanks again,Now I understand why you put this to a plugin.

As you said, we can better manage our assets. Great advice!

Have a nice day :slight_smile:

Btw, I have updated the Github code to also contain a custom category (instead of misc) if you ever need that.

I think that I have seen how to set custom category from other documents.but if you have time, this will help a lot.

Already done https://github.com/Pavel-Konarik/CustomAssetDemo

It works well. Fantastic!