Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


AssetKey

Identifies a single asset to load through an asset provider. The key pairs a provider specific address with an expected asset type, and optionally the name of a sub-asset at that address.
Read time 2 minutesLast updated 14 days ago

Definition

public readonly struct AssetKey : IEquatable<AssetKey>

Remarks

The AssetKey.Address is opaque to the cache and is interpreted by the active provider: ReferencedAssetProvider treats it as the key into its address-to-reference map, ResourceFolderProvider treats it as a
Resources
path, and a provider installed from a package (for example an Addressables-backed one) can interpret it as its own address. AssetKey.Type is part of the identity because one address can hold objects of several types, so two keys with the same address but a different type are distinct.
Create a key for a texture and inspect its parts.

Examples

using Unity.Localization.Providers;using UnityEngine;namespace Unity.Localization.Samples{ public class AssetKeyOverviewExample { public void Run() { var key = new AssetKey("UI/Flags/Fr", typeof(Texture2D)); Debug.Log(key.Address); // UI/Flags/Fr Debug.Log(key.Type.Name); // Texture2D Debug.Log(key.IsValid); // True } }}

Constructors

Constructor

Description

AssetKey(System.String,System.Type,System.String)Creates a key for the given address, interpreted by the active provider.

Properties

Property

Description

AddressThe provider-specific address that identifies the asset.
IsValidWhether this key carries an address.
SubAssetNameThe name of the sub-asset at the address, or null when the key targets the whole asset.
TypeThe expected asset type.

Methods

Method

Description

EqualsChecks whether this key equals another object.
GetHashCodeComputes a hash code for this key.
ToStringReturns a readable string describing this key.

Operators

Operator

Description

operator ==Compares two keys for equality.
operator !=Compares two keys for inequality.