Manage metadata

Manage asset metadata in Unity Asset Manager using the Python SDK, including how to create, update, and delete metadata fields.
Read time 3 minutesLast updated 8 days ago

Before you begin

To access any metadata from an asset, dataset or file, make sure the app has all the right accesses. Read more about managing Identity.

How do I...?

Create a metadata field definition

To create a metadata field, follow these steps:
  1. Create a
    CreateField
    object and fill in the necessary information.
  2. Call
    create_field_definition
    with the organization id and your
    CreateField
    object. The possible for
    FieldDefinitionType 
    are:
    • BOOLEAN
    • SELECTION
    • NUMBER
    • TEXT
    • TIMESTAMP
    • URL
    • USER
create_field = CreateFieldDefinition(
  key = "my_new_field",
  display_name = "My Field",
  type = unity_cloud.assets.FieldDefinitionType.SELECT,
  accepted_values = ["value1", "value2", "value3"],
  multiselection = False
)

unity_cloud.assets.create_field_definition(org_id = "0123456", create_field = create_field)

Update a metadata field definition

To update a metadata field, follow these steps:
  1. Create an
    UpdateField
    object along with the information to update.
  2. Call
    update_field_definition
    with the organization id and your
    UpdateFieldobject
    .
update_field = UpdateFieldDefinition(
  key = "my_new_field",
  display_name = "My Field with a new name",
  accepted_values = ["value1", "value2", "value3", "value4"]
)

unity_cloud.assets.update_field_definition(org_id = "0123456", update_field = create_field)

Add accepted values to a SELECT metadata field

To add accepted values to a metadata field of type
SELECT
, call
add_accepted_values_to_field_definition
with the new values.
This action removes the necessity of calling
update_field_definition
with all the already existing values.
unity_cloud.assets.add_accepted_values_to_field_definition(org_id = "0123456", field_key = "my_new_field", accepted_values = ["value5", "value6"])

Remove accepted values from a SELECT metadata field

To remove accepted values to a metadata field of type
SELECT
, call
remove_accepted_values_from_field_definition
with the values you want removed.
This action removes the necessity of calling
update_field_definition
with the values you want to keep.
unity_cloud.assets.remove_accepted_values_from_field_definition(org_id = "0123456", field_key = "my_new_field", accepted_values = ["value5", "value6"])

Delete a metadata field definition

To delete a metadata field, call delete_field_definition with its organization id and field key.
unity_cloud.assets.delete_field_definition(org_id = "0123456", field_key = "my_new_field")

List all field definitions

To retrieve all metadata field from an organization, call
list_field_definitions
with the organization id and whether or not you want deleted field included in the list.
  • (Optional) Add the parameter name_sorting_order to sort the results alphabetically either in ascending or descending.
  • (Optional) Add the parameter
    limit_to
    to limit the amount of results returned. Leave it unchanged or set it to 0 to return everything.
  • (Optional) Add the parameter
    skip
    to specify the number of collection to skip in the results. Use in combination with limit_to to page through results.
fields = unity_cloud.assets.list_field_definitions(
org_id = "0123456",
include_deleted = False,
name_sorting_order = SortingOrder.ASCENDING,
limit_to = 10,
skip = 0)

Get a field definition

To retrieve a metadata field from an organization, call
get_field_definition
with the organization id and the key of the field.
field = unity_cloud.assets.get_field_definition(org_id = "0123456", field_key = "my_new_field")

Manage metadata

When managing
Metadata
dictionaries, make sure the dictionaries have existing metadata field keys and consistent values according to their type.
For a field with a
SELECT
type, accepted_values can either be a string or an array of strings. This distinction depends on the value set for multiselection:
  • If set to 
    TRUE
    , the 
    accepted_values
     is an array of strings.
  • If set to 
    FALSE
    , the 
    accepted_values
     is a string.
  • Use the following code sample to create an entity:
metadata = dict()
metadata["Language"] = "C#"

asset_creation = AssetCreation(
  name = "your-asset-name",
  description = "your-asset-description",
  type = unity_cloud.assets.asset_type.MODEL_3D,
  metadata = metadata
)
  • Use the following code sample to update an entity:
    metadata = dict()
metadata["Language"] = "C#"

asset_update = AssetUpdate(
  name = "your-asset-name",
  metadata = metadata
)
  • Use the following code sample to fetch an entity's metadata:
asset_metadata = unity_cloud.assets.get_asset_metadata(
  org_id = "012345",
  project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
  asset_id = "0123456789",
  keys = [])

asset_prog_language = asset_metadata["Language"]

dataset_metadata = unity_cloud.datasets.get_dataset_metadata(
  org_id = "012345",
  project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
  asset_id = "0123456789",
  dataset_id = "0123456789",
  keys = [])

file_Metadata = unity_cloud.files.get_file_metadata(
  org_id = "012345",
  project_id = "1234abcd-ab12-cd34-ef56-123456abcdef",
  asset_id = "0123456789",
  dataset_id = "0123456789",
  cloud_file_path = PurePosixPath("path/to/file.ext"),
  keys = [])