Getting Metadata
How to retrieve metadata from an asset
Getting Metadata
There are two options when retrieving Metadata values on an asset:
A) From an AssetData reference (lightweight header info of an asset):
B) From a loaded asset reference:
My convenience function setup for getting metadata looks like this as a baseline:
Note: In this setup, metadata is returned as a string
- you'll need to convert it to another data type if desired
Extending Metadata Data Types in Python
While the default behavior of Unreal is to store and return strings, there's nothing to say we can't extend it in our Python API!
Declaring our Data Types
The first step is to create a dictionary in Python mapping our metadata names to their data types - anything that is not a string needs to be added:
Expanding The Get Function
We can then use this dictionary in our getter function to convert the string metadata value back to its desired type:
The new function above works like this:
Get the Metadata Value from the Unreal Asset
Make sure the data is valid (not None)
Get the Metadata's Data Type from the Type Map
Convert the Metadata Value to its intended type
Note: Certain data types, such as bools, require custom handling to convert back. Converting a String to a Bool only checks if the string has a length, bool("False")
returns True
Demo
This is the metadata on our test asset:
The data is stored as a string on the Unreal Asset, but now our Python Function automatically returns them as their intended types:
Last updated