How to do it...

  1. Create a new C++ class based on UObject called MyCustomAsset:

  1. Open up the script and update the code of the .h file to the following:
#pragma once

#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "MyCustomAsset.generated.h"

/**
*
*/
UCLASS()
class CHAPTER_10_API UMyCustomAsset : public UObject
{
GENERATED_BODY()

public:
UPROPERTY(EditAnywhere, Category = "Custom Asset")
FString Name;

};
  1. Next, create a class based on UFactory:

  1. Give the script a name of CustomAssetFactory and press the Create Class button.
  2. Open the script in Visual Studio and update the CustomAssetFactory.h file to the following:
#pragma once

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

UCLASS()
class CHAPTER_10_API UCustomAssetFactory : public UFactory
{
GENERATED_BODY()

public:
UCustomAssetFactory();

virtual UObject* FactoryCreateNew(UClass* InClass,
UObject* InParent, FName InName, EObjectFlags Flags,
UObject* Context, FFeedbackContext* Warn, FName
CallingContext) override;
};
  1. Then, switch over to the CustomAssetFactory.cpp file and implement the class:
#include "CustomAssetFactory.h" 
#include "Chapter_10.h"
#include "MyCustomAsset.h"


UCustomAssetFactory::UCustomAssetFactory()
:Super()
{
bCreateNew = true;
bEditAfterNew = true;
SupportedClass = UMyCustomAsset::StaticClass();
}

UObject* UCustomAssetFactory::FactoryCreateNew(UClass*
InClass, UObject* InParent, FName InName, EObjectFlags
Flags, UObject* Context, FFeedbackContext* Warn, FName
CallingContext)
{
auto NewObjectAsset = NewObject<UMyCustomAsset>(InParent,
InClass, InName, Flags);
return NewObjectAsset;
}
  1. Compile your code and open the editor.
  1. Right-click in Content Browser, from the Content folder and, under the Miscellaneous tab of the Create Advanced Asset section, you should see your new class and be able to create instances of your new custom type: