Data Assets in Unreal Engine

What is a Data Asset in Unreal Engine?

Data Assets are used in Unreal Engine to store information.

They offer an alternative to Data Tables. When Data Tables become very large, they may take too long to go through and read all the values inside them sequentially because of their many rows.

The concept behind data assets is to create a unique asset for every row that would typically be found in a data table. This approach makes them more challenging to organize and quickly review. However, they usually perform better and result in fewer crashes and errors.

Additionally, Data Tables are read-only elements, while in Data Assets, you can actually write information.

I recommend reading our lessons on structures and data tables before delving into data assets. Doing so will likely make this lesson easier to understand.

So let’s learn how to use them, so you can decide for yourself in which cases you want to use a Data Table or a Data Asset.

1. Create a Primary Data Asset

To use data assets, we first need to create a Primary Data Asset. You can think of this step as similar to creating a Structure for a Data Table. Just as we create the structure before the data table, the same principle applies here.

To create the Primary Data Asset, simply right-click or use the ‘+ Add‘ button in the Content Browser, then select ‘Blueprint Class‘.

Unreal Engine Create a Blueprint Class

Next, in ‘All Classes’ search for: PrimaryDataAsset.

Primary Data Asset Unreal Engine

2. Add variables to the Data Asset

First, open the Data Asset you just created.

Now, navigate to the variables panel and create variables as you would typically do inside Blueprints.

Create Variable in Unreal Engine
Example of Variables in Unreal Engine

Tip: As you can see, you are in an Event Graph. This means that you can also use blueprint logic here, such as functions and event dispatchers. This is extremely useful for making calculations like applying selling discounts or adjusting damage.

How do you create a Data Asset?

Now, we are going to create multiple data assets in Unreal Engine. Think of this step as similar to creating the rows in a data table.

To create a Data Asset, simply right-click or use the ‘+ Add’ button in the Content Browser, then select ‘Miscellaneous → Data Asset‘.

Then select the primary data asset you created in step 1 from the list. Alternatively, you can also use any of the default data assets provided by Unreal Engine.

Create Data Asset Unreal Engine

Next, simply give the data asset a name corresponding to an item, an enemy, or attacks, or whatever you want to list, and open it.

Inside, you just have to fill in the variable data types that you created in step 2.

Once you are done, you can either repeat this step or simply duplicate the data asset to create as many data assets as you need.

Make sure to organize everything well in the folders of the Content Drawer, as the list of data assets grows, it can become increasingly difficult to find and organize them.

Data Assets Example in Unreal Enigne

Tip: You can also use Data Assets to store Boolean values to track actions that the player has already completed. For instance, if something has occurred in the game, such as completing a tutorial or defeating a boss, you can save a data asset with a simple true or false value. This practice is well-explained in the following YouTube tutorial.

Using Data Assets in Blueprints

Data Asset Variables

To access the Data Asset variables, first create a variable and set its type to the primary data asset you created in step 1. In my case, it is named ‘Item Data Asset‘, but select the one you created and choose ‘Object Reference‘.

Compile the Blueprint and set the default value of the variable to the data asset you want to use. In this case, I will use the data asset for my banana item.

When getting or setting the data asset variable, you can easily access all the variables inside it, similar to how you would when casting. The same applies for accessing functions.

Data Asset Set Get Variables

Data Asset Map

Instead of using a regular single variable, you can also use a map.

For example, you can use a map for creating an inventory. Then, connect the map to any map nodes, such as ‘add’, to add items to your inventory.

I will cover lessons on Maps in the future, so stay tuned!

Data Asset Map

You can learn more in the official documentation.

Or if you are a more advanced user, take a look at this roundtable discussion.

Hope this helps! Keep on creating!

Unreal Engine Learning Path