Manage assets
How to add and manage assets with Python SDK.
Read time 4 minutesLast updated a year ago
Before you begin
To access any assets, make sure the app has the right permissions. Read more about managing Identity.
Create an asset
To add an asset into a project, follow these steps:
- Use the method by passing all the information inside
create_asset.AssetCreation - At least define and
Namevalues to create an asset. The possible values forTypeare:Type2D Asset3D ModelAudioMaterialScriptVideoUnity EditorOther
The created asset is saved as a draft.
asset_creation = AssetCreation( name = "your-asset-name", description = "your-asset-description", type = unity_cloud.assets.AssetType.MODEL_3D, tags = ["your-tag-1", "your-tag-2", "your-tag-3"] ) asset = unity_cloud.assets.create_asset( asset_creation = asset_creation, org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef" )
Update an asset
To change the name, the description, the type, the tags, or the file used for the preview you need to:
- Create an method.
AssetUpdate - Call the method.
update_asset
asset_update = AssetUpdate( name = "your-asset-name", description = "your-asset-description", type = unity_cloud.assets.AssetType.MODEL_3D, tags = ["your-tag-1", "your-tag-2", "your-tag-3"], preview_file = "Path/To/File.ext" ) unity_cloud.assets.update_asset( asset_update = asset_update, org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef' )
Get an asset
To fetch a single asset, call .
get_assetasset = unity_cloud.assets.get_asset( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef' )
Get an asset by its label
When the version of the asset is not known, you can fetch an asset by its label using the method. Keep the parameter empty to fetch the default version of the asset.
get_asset_by_labellabelasset = unity_cloud.assets.get_asset_by_label( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", label = "your-asset-label" )
Get a list of all assets within a project
To fetch all assets contained in a given project, call .
get_asset_listassets = unity_cloud.assets.get_asset_list( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef" )
Perform an advanced search for assets
To search for assets across an organization, follow these steps:
- Create your filters as dictionnaries or objects that will contain the conditions.
- Create an array that will contain the projects in which to look up. Leave the array empty to search across all projects in the organization.
- Create an array that will contain the collections in which to look up. Leave the array empty to search across all collections and assets not linked to a collection.
- Call with the organization ID, your project IDs, your filters, the amount of matches required in the any_filter, the collections, and optionally the maximum number of results returned and the amount to skip for paging purpose.
search_assets_in_projects
include_filter = dict()exclude_filter = dict()any_filter = dict()include_filter[SearchableProperties.NAME] = StringFilter(StringLookUpTypes.REGEX, "asset\-.*")project_ids = []collections = []search_result = unity_cloud.assets.search_assets_in_projects(org_id, project_ids, include_filter = include_filter, exclude_filter = exclude_filter, any_filter = any_filter, any_query_minimum_match = 1, collections = collections, limit_to = 10, skip = 0)
Create filter for a search query
To create an , an , or an , you can use the enum as a helper. This enum is provided with a comment on how each each properties should be created. You are not limited to properties in this enum and can write your own, as long as the properties you're writing exist either in an asset, dataset, or file.
include_filterexclude_filterany_filterSearchablePropertiesTo create a filter on a string property, you can either write a simple equal condition, or use an advanced .
StringFilterinclude_filter = dict()include_filter[SearchableProperties.DESCRIPTION] = "Description must be exactly equals to this"include_filter[SearchableProperties.NAME] = StringFilter(StringLookUpTypes.wildcard, "incompl*te n*me")
To create a filter on a date property, you can either write a simple equal condition, or use an advanced . Date must be passed.
DateRangeConditiondate_to_compare = datetime.now().isoformat()exclude_filter = dict()exclude_filter[SearchableProperties.DATASETS_CREATED] = date_to_comparedata_condition = DateRangeCondition(RangeConditionTypes.LESS_THAN, date_to_compare)date_filter = DateRangeFilter([numeric_condition])exclude_filter[SearchableProperties.FILES_UPDATED] = DateRangeFilter([data_condition])
To search using a custom metadata field, write as the property. To find the key of a custom metadata field, refer to metadata documentation.
Complex filters cannot be used with custom metadata fields, only simple equal conditions.
metadata.<your-metadata-key>exclude_filter = dict()exclude_filter["metadata.MyCustomMetadataFieldKey"] = "expected-value"
Link assets to a project
To link assets to multiple projects, use the method with the argument.
link_assets_to_projectproject_idunity_cloud.assets.link_asset_to_project( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_ids = ["0123456789abcdefghijklmn"], new_project_id = "4567efgh-ab12-cd34-ef56-123456abcdef" )
Remove assets link to a project
To remove assets link to multiple projects, use the method with the argument.
unlink_assets_from_projectproject_idunity_cloud.assets.unlink_asset_from_project( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_ids = ["0123456789abcdefghijklmn"] )
Get an asset preview file URL
To get the URL of the preview file of an asset, use the method.
get_preview_file_urlpreview_file_url = unity_cloud.assets.get_preview_file_url( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef' )
Add an asset reference to an asset
To add a reference to an asset, use the method. You can either add a reference by using an asset version or a version label assigned to it.
add_asset_referenceunity_cloud.assets.add_asset_reference( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", source_asset_id = "0123456789abcdefghijklmn", source_asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef', target_asset_id = "4567efgh-ab12-cd34-ef56-123456abcdef", target_asset_version = '4567efgh-ab12-cd34-ef56-123456abcdef', target_asset_label = "your-asset-label" )
List the references of an asset
To list the references of an asset, use the method. The parameter can be , or if you want everything.
list_asset_referencescontextContext.SOURCEContext.TARGETContext.BOTHreferences = unity_cloud.assets.list_asset_references( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef', context = Context.SOURCE )
Remove an asset reference
Using the result of the previous method, you can remove a reference to an asset by using the method with the id of a reference.
remove_asset_referenceunity_cloud.assets.remove_asset_reference( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef', reference_id = "4567efgh-ab12-cd34-ef56-123456abcdef" )