Hi All,
So I was checking the ActionRPG project from epic and I saw the Item system they created:
UCLASS()
class ACTIONRPG_API URPGAssetManager : public UAssetManager
{
GENERATED_BODY()
public:
// Constructor and overrides
URPGAssetManager() {}
virtual void StartInitialLoading() override;
/** Static types for items */
static const FPrimaryAssetType PotionItemType;
static const FPrimaryAssetType SkillItemType;
static const FPrimaryAssetType TokenItemType;
static const FPrimaryAssetType WeaponItemType;
/** Returns the current AssetManager object */
static URPGAssetManager& Get();
/**
* Synchronously loads an RPGItem subclass, this can hitch but is useful when you cannot wait for an async load
* This does not maintain a reference to the item so it will garbage collect if not loaded some other way
*
* @param PrimaryAssetId The asset identifier to load
* @param bDisplayWarning If true, this will log a warning if the item failed to load
*/
URPGItem* ForceLoadItem(const FPrimaryAssetId& PrimaryAssetId, bool bLogWarning = true);
};
And items have that primary asset type:
UCLASS(Abstract, BlueprintType)
class ACTIONRPG_API URPGItem : public UPrimaryDataAsset
{
GENERATED_BODY()
public:
/** Constructor */
URPGItem()
: Price(0)
, MaxCount(1)
, MaxLevel(1)
, AbilityLevel(1)
{}
/** Type of this item, set in native parent class */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Item)
FPrimaryAssetType ItemType;
and each item definition extends this:
UCLASS()
class ACTIONRPG_API URPGPotionItem : public URPGItem
{
GENERATED_BODY()
public:
/** Constructor */
URPGPotionItem()
{
ItemType = URPGAssetManager::PotionItemType;
}
};
Is this really the unreal way of doing things ? I can imagine using an enum would be a lot easier. Is there any explanation for this ?