Class AssetReference
Reference to an addressable asset. This can be used in script to provide fields that can be easily set in the editor and loaded dynamically at runtime. To determine if the reference is set, use RuntimeKeyIsValid().
Implements
Inherited Members
Namespace: UnityEngine .AddressableAssets
Assembly: Unity.Addressables.dll
Syntax
[Serializable]
public class AssetReference : IKeyEvaluator
Constructors
Name | Description |
---|---|
Asset |
Construct a new AssetReference object. |
Asset |
Construct a new AssetReference object. |
Fields
Name | Description |
---|---|
m_Asset |
The GUID of an asset |
Properties
Name | Description |
---|---|
Asset | The loaded asset. This value is only set after the AsyncOperationHandle returned from LoadAssetAsync completes. It will not be set if only InstantiateAsync is called. It will be set to null if release is called. |
Asset |
Stores the guid of the asset. |
Cached |
Cached Editor Asset. |
Derived |
|
Is |
Get the loading status of the internal operation. |
Operation |
The AsyncOperationHandle currently being used by the AssetReference. For example, if you call AssetReference.LoadAssetAsync, this property will return a handle to that operation. |
Runtime |
The actual key used to request the asset at runtime. RuntimeKeyIsValid() can be used to determine if this reference was set. |
Sub |
Stores the guid of the sub object (if available). |
Sub |
Stores the name of the sub object. Some assets, such as models and sprite atlases, contain mutliple objects. These objects can be loaded by specifying their name and type. |
editor |
Used by the editor to represent the main asset referenced. |
Methods
Name | Description |
---|---|
~Asset |
|
Instantiate |
InstantiateAsync the referenced asset as type TObject. |
Instantiate |
InstantiateAsync the referenced asset as type TObject. |
Is |
Returns the state of the internal operation. If the load has not been started or if it has been released, the operation will not be valid and this will return false. This can be used to determine if an AssetReference has started loading or not. |
Load |
Load the referenced asset as type TObject. |
Load |
Loads the reference as a scene. |
Release |
Release the internal operation handle. |
Release |
Release an instantiated object. |
Runtime |
Checks if the current RuntimeKey is valid. |
Set |
Sets the main asset on the AssetReference. Only valid in the editor, this sets both the editorAsset attribute, and the internal asset GUID, which drives the RuntimeKey attribute. If the reference uses a sub object, then it will load the editor asset during edit mode and load the sub object during runtime. For example, if the AssetReference is set to a sprite within a sprite atlas, the editorAsset is the atlas (loaded during edit mode) and the sub object is the sprite (loaded during runtime). If called by AssetReferenceT, will set the editorAsset to the requested object if the object is of type T, and null otherwise. Object to reference |
Set |
Sets the sub object for this asset reference. |
To |
String representation of asset reference. |
Un |
Unloads the reference as a scene. |
Validate |
Validates that the referenced asset allowable for this asset reference. |
Validate |
Validates that the referenced asset allowable for this asset reference. |