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):
asset_path = "/Game/some/asset/path"
asset_data = unreal.EditorAssetLibrary.find_asset_data(asset_path)
value = asset_data.get_tag_value("asset_name")
B) From a loaded asset reference:
asset_path = "/Game/some/asset/path"
asset = unreal.load_asset(asset_path)
value = unreal.EditorAssetLibrary.get_metadata_tag(asset, "asset_name")
My convenience function setup for getting metadata looks like this as a baseline:
def get_metadata(asset, key):
"""Get the loaded object or AssetData's metadata"""
if isinstance(asset, unreal.AssetData):
return asset.get_tag_value(key)
else:
return unreal.EditorAssetLibrary.get_metadata_tag(asset, key)
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:
METADATA_TYPE_MAP = {
"managed_asset": bool,
"asset_version": int
}
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:
def get_metadata(asset, key):
"""Get the loaded object or AssetData's metadata as its expected type"""
# Get the unreal metadata value
if isinstance(asset, unreal.AssetData):
value = asset.get_tag_value(key)
else:
value = unreal.EditorAssetLibrary.get_metadata_tag(asset, key)
# If the metadata was found & valid let's convert it!
if value and value.lower() != "none":
# Get this metadata key's expected value type, default is str (as-is)
value_type = METADATA_TYPE_MAP.get(key, str)
if value_type == bool:
# bools are a special case as bool(str) only checks for length
return value.lower() == "true"
else:
# most singular value types may be directly converted
return value_type(value)
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
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