Introduction
In the world of digital workflows, handling metadata is a common practice. In most CG pipelines, metadata is stored in external text files, allowing tools to easily read and write data. But when dealing with Unreal Engine, which operates predominantly in real-time, the challenge arises to access metadata through Blueprint scripting, requiring the metadata to be in Unreal’s native format.
After some research, I came across a proposal from a staff member in the Unreal Developer Community. In this article, we’ll explore the different methods from the proposal and discuss the approach I’ve settled on.
Data Table
Data tables offer a flexible way to structure data. However, it’s important to note that you need to define the data structure in advance to use them effectively
To have a working data table we need to first create a data structure where each entry of the data table will conform to.
Data Table (left) with corresponding Data Structure (right)
How to Read Data Table
1 | import unreal |
How to Write Data Table
It seems like data tables are ready-only at first, as there are only get_data
function sets:
https://forums.unrealengine.com/t/set-data-table-row/85844
However, there are in fact a way to write to data table, and that is with the use of .csv or .json.
1 | unreal.DataTableFunctionLibrary.fill_data_table_from_json_file(data_table, json_file_path, data_structure) |
I won’t go into how to update .csv or .json files, but do note that the formatting of the text file is important, and you can get a reference of what the file would look at by simply export out the data table with some test data like so:
Metadata
To access metadat for each asset, you can do a right-click “Asset Actions”, “Show Metadata”.
This is quite handy since, based on our need, it can be bound to an asset.
And if we want to separate the binding between the asset and the data, we can also do so by creating an empty blueprint asset and use it as a central container to store metadata.
The limitation however is that all the values are string type.
How to Read Metadata
1 | import unreal |
How to Write Metadata
We can also easily set and remove the metadata tag and values like so.
1 | unreal.EditorAssetLibrary.set_metadata_tag(asset, "version", "4") |
Blueprint Variable
And lastly, I want to introduce the approach I ended up with: map variable in a custom blueprint asset.
We first create a Blueprint asset using the basic Object class, and then add our custom ‘Version’ variable as a string: integer map this is basically equivalent to:
1 | "Version": {str: int} |
Through scripting, we first need to get the default class object of the blueprint, which can be achieved like so:
1 | import unreal |
The advantage here lies in having a single blueprint asset capable of storing numerous variables, each natively typed to Unreal. Nevertheless, I haven’t yet attempted to create variables solely through code.
How to Read Blueprint Variable
1 | def get_version(dco, name): |
How to Write Blueprint Variable
Note that we use the get_editor_property()
to set the metadata
1 | def set_version(dco, name, version): |
Example
Since, this approach is the one I have experimented the furthest along, here’s an example on how I access it in another Blueprint:
Another way is to use ‘Get Class Default Object’ and ‘Cast To BP Test Metadata’ which return ‘As BP Test Metadata’ and can then access the “Version” variable.
References
Unreal Forum - How to store text data with Python?