Make a Prefab Spawn Class Getter using a Data Asset as Input
About
In this short tutorial we are using the power of Data Assets with a new Prefab Class Getter subclass.
The goal is to assign a Data Asset to a class getter and pick up the actor class in it. This is very useful if you are already using Data Assets in your project.
Step 1 - Create the Data Asset
1.1 Create the Data Asset class
In the Content Browser, right click and create a new Blueprint Class.
Then inside All Classes type DataAsset and pick PrimaryDataAsset (you can use any other subclass, including yours).

Name it DABP_PrefabDefinition
.

And finally add a new variable of type Actor (Soft Class Reference).

1.2 Create a Data Asset instance
In the Content Browser, right click and create a new Data Asset.

Then select the class we made previously and name it.

You should see the Actor Class we added previously, select any BP actor class you would like to spawn.

We are now done for the Data Asset part.
Step 2 - Create the Prefab Spawn Class Getter Subclass
2.1 Create a new Prefab Spawn Class Getter class
In the Content Browser right click and create a new Blueprint Class inheriting UPSActorPrefabSpawnClassGetterBase
and name it BP_PrefabSpawnClassGetter_DataAsset
.

Add a new variable of type DABP_PrefabDefinition
(Object Reference). Mark is as Instance Editable.
2.2 Implement the logic
From the Functions -> Override menu, select GetSoftPrefabClass
and ClearSoftPrefabClass
.

Inside GetSoftPrefabClass
get a reference to your Data Asset variable and get the Actor Class like so:

Inside ClearSoftPrefabClass
set the Data Asset variable to null like so:

ClearSoftPrefabClass
is used by the editor when things such as infinite nesting loops are detected. It is important to allow the editor to clear unwanted references.
Final result
On your Prefab Reference Component set the Prefab Spawn Class Getter to BP_PrefabSpawnClassGetter_DataAsset
and pick your example Data Asset.

Last updated