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!