Download

UDataAsset vs Blueprintable UObject

So I see two effective ways of building static game data, in this case imagine creating simple items for an RPG style game. I could use data assets:



UClass()
class UItem : public UDataAsset
{
UProperty()
float AttackPower;

UProperty()
float Defense;
}
 

Or I could use a blueprintable UObject.



UClass(Blueprintable)
class UItem : public UObject
{
UProperty()
float AttackPower;

UProperty()
float Defense;
}


In the second case when I want to create a new item I just create a new blueprint that inherits from UItem. Any thoughts on which is the preferred approach? The UDataAsset approach is simple and this is the sort of thing they were intended for. The blueprints on the other hand are a bit odd, for example these would need to be data only blueprints, any sort of scripting logic in them would be nonsensical. You could use the blueprints to create a hierarchy of items, and even have designers add new fields of their own. I’m not sure that’s a good thing… Are there any performance or memory concerns with creating 1000 item blueprints?

A BlueprintType Data Asset

Dear Stefan,

[FONT=Comic Sans MS]Welcome to the forums Stefan!

I’ve used both Data Assets and UObjects for storing data as you are describing, and I’ve used both methods pretty extensively in several different code bases.

The only immediate issue I had with Data Assets vs UObject Blueprints was that I could not store a variable created in BP to a UDataAsset.

For a system as fundamental as inventory, its important that the rest of your team be able to refer to your items in BP!

So you can correct the only short-coming of a UDataAsset by adding BlueprintType to it:



/*
  By Rama
*/
#pragma once

#include "ActionTypes.generated.h"

UCLASS(BlueprintType) //<~~~ So can create vars of this type in BPs 
class UActionTypes : public UDataAsset
{ 
	GENERATED_BODY()
public:  
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Action Types")
	TArray<FString> ActionTypes;
	
};



**UDataAsset**

I personally feel the UDataAsset is more light-weight and definitely has a **cleaner UI** than a UObject Blueprint for game assets that are strictly **data-only** and do not have any logic to them.

Therefore my answer to your question is a **BlueprintType UDataAsset** so people using BP can still make ptrs to your fundamental data type but the UI is as clean as possible for a strictly data-only game asset :)

Neat Icon!

Entertainingly enough, there is already a neat icon for Data assets as BP variables in UE4, though it does not seem that you can create such variables until you add BlueprintType as I show above.

Pic 1:

Because I made the UDataAsset BlueprintType as shown above (C++), I can now create a BP var to it in my level BP.

974f1edc0fbf4542f63cbe949f288a6120b69e02.jpeg

Pic 2:

And because I made it the blue kind (an object ptr not a class type)

I can now set the BP-created variable in my Level BP defaults (Window->Class Defaults)

1e56f7308cb5a1b928bedc186ef35683af1b73a8.jpeg

Enjoy!

:slight_smile:

Rama

Great, this is exactly the information I was looking for. Thanks a lot Rama!