Creating a new Asset type

At some point in your project, you might need to create a new custom Asset class, for example, an Asset to store conversation data in an RPG.

In order to properly integrate these with Content Browser, you'll need to create a new Asset type.

How to do it…

  1. Create a custom Asset based on UObject:
    #pragma once
    
    #include "Object.h"
    #include "MyCustomAsset.generated.h"
    
    /**
     * 
     */
    UCLASS()
    class UE4COOKBOOK_API UMyCustomAsset : public UObject
    {
      GENERATED_BODY()
      public:
      UPROPERTY(EditAnywhere, Category = "Custom Asset")
      FString Name;
    };
  2. Create a class called UCustomAssetFactory based on UFactory, overriding FactoryCreateNew:
    #pragma once #include "Factories/Factory.h" #include "CustomAssetFactory.generated.h" /** * */ UCLASS() class UE4COOKBOOK_API ...

Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.