More documentation around UDataAsset

As a long time Unity developer, one of the things I had struggled with for a while is wanting a replacement for Unity’s ScriptableObject - that is, a class where you can subclass it and then create new instances of that as assets in your project.

Yesterday I found UDataAsset while browsing the c++ api docs, and it’s exactly what I wanted! So I ended up searching the main docs for UDataAsset and didn’t really find anything. It’d be nice to have a page in the docs that walks through creating an using a new Data Asset type and using it, along with a mention on the “UE4 for Unity Developers” page for people who are looking for the ScriptableObject equivalent.

Here are my notes that I took while learning it yesterday trying to get my UDataAsset stuff working in case it’s helpful:

  • UDataAsset subclass instances can be created and stored in your content directory as an asset
  • Create a new C++ subclass of UDataAsset
  • Make sure it’s UCLASS(BlueprintType)
  • Make sure you have UPROPERTY(EditAnywhere) on the members you want to be able to modify in the editor
  • UDataAsset objects can have blueprint callable functions if you tag them with UFUNCTION(BlueprintCallable) or UFUNCTION(BlueprintPure)
  • Once you have the class compiled, create one in your content browser with Add New > Miscellaneous > Data Asset
  • That will pop up a dialog that lets you choose the type of UDataAsset you want, including your new one.
  • Name it, and then double click it to open it, from there you should be able to edit the contents in the editor window.
  • Blueprints can then have a reference to your data asset type and use it like they would anything else

Thanks again for all the great work you do on the docs, you make learning a big engine easier!

It’s unfortunate no one has replied…

I played a lot with UDataAsset and it is very practical, can combine working with DataTables, etc.

The “Data Driven Gameplay Elements” has not been modified since 4.9 and it shoud include some information about UDataAsset now…

Is it possible to create a candidate document on the Wiki pages and have it migrated to the unreal documentation?

@rje @josimard
Thank you for your feedback! I’ve passed the information on to the writer for that area.

hey @rje,
I’d like to add, the maybe obvious fact that, you should not write data to a data asset, only read.
And I’d like to ask how common it is to put logic in the data asset’s cpp file? Is it meant to only read data or is it just as common to ask for processed data from some return functions inside the data asset?

We usually create some getters to process already existing data in the DA, but we don’t store anything dynamically.

It has been requested in 2017, so that’s only 2 years, which is just too fresh to see any results on Epic standards. Maybe we’ll see it documented in 2021 :slight_smile: