Knowledge Base: How To: Create New Assets in C++

I’m Taiwanese, forgive about my english.
Here’s the thing, i’ve encountered a problem that I want to programmatically generate assets, like inventory items. Yeah, I know the way of using AssetData, but some object is already set, so I still want to create a blueprint asset into content.

Here is it.
Before defining your own generation code, you have to define your object factory first.

UCLASS( hidecategories = Object, collapsecategories)
class LYRAGAME_API UBPFactory_MyObject: public UBlueprintFactory
{
	GENERATED_BODY()

	UBPFactory_MyObject();

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

UBPFactory_MyObject::UBPFactory_MyObject()
{
	bCreateNew = true;
	bEditAfterNew = true;
	SupportedClass = UBlueprint::StaticClass();
	ParentClass = ULyraInventoryItemDefinition::StaticClass();
	BlueprintType = BPTYPE_Normal;
}

UObject* UBPFactory_MyObject::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn, FName CallingContext)
{
	return FKismetEditorUtilities::CreateBlueprint(ParentClass, InParent, Name, BlueprintType, UBlueprint::StaticClass(), UBlueprintGeneratedClass::StaticClass(), CallingContext);
}


ObjectFactory is the main method of creating your object.

After creating BlueprintFactory for your object, back to CreatePackage section.

// Create object and package
UPackage* package = CreatePackage(*PackageName);
UBPFactory_MyObject* MyFactory = NewObject<UBPFactory_MyObject>(UBPFactory_MyObject::StaticClass()); // Use tour custom object factory

UObject* NewObject = AssetToolsModule.Get().CreateAsset(Name, OutPackagePath, UBlueprint::StaticClass(), MyFactory);

FSavePackageArgs SaveArgs = FSavePackageArgs();
SaveArgs.SaveFlags = RF_Public | RF_Standalone;

UPackage::Save(package, NewObject, *FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension()), SaveArgs);

// Inform asset registry
AssetRegistry.AssetCreated(NewObject);

// Tell content browser to show the newly created asset
TArray<UObject*> Objects;
Objects.Add(NewObject);

That’s much all for generating customed blueprint assets.