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().
Namespace: UnityEngine.AddressableAssets
Syntax
[Serializable]
public class AssetReference : IKeyEvaluator
Constructors
AssetReference()
Construct a new AssetReference object.
Declaration
public AssetReference()
AssetReference(String)
Construct a new AssetReference object.
Declaration
public AssetReference(string guid)
Parameters
Type | Name | Description |
---|---|---|
String | guid | The guid of the asset. |
Properties
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.
Declaration
public virtual object Asset { get; }
Property Value
Type | Description |
---|---|
Object |
AssetGUID
Declaration
public virtual string AssetGUID { get; }
Property Value
Type | Description |
---|---|
String |
IsDone
Get the loading status of the internal operation.
Declaration
public bool IsDone { get; }
Property Value
Type | Description |
---|---|
Boolean |
RuntimeKey
The actual key used to request the asset at runtime. RuntimeKeyIsValid() can be used to determine if this reference was set.
Declaration
public virtual object RuntimeKey { get; }
Property Value
Type | Description |
---|---|
Object |
Implements
SubObjectName
Declaration
public virtual string SubObjectName { get; set; }
Property Value
Type | Description |
---|---|
String |
Methods
Instantiate(Transform, Boolean)
InstantiateAsync the referenced asset as type TObject.
Declaration
[Obsolete]
public AsyncOperationHandle<GameObject> Instantiate(Transform parent = null, bool instantiateInWorldSpace = false)
Parameters
Type | Name | Description |
---|---|---|
Transform | parent | The parent of the instantiated object. |
Boolean | instantiateInWorldSpace | Option to retain world space when instantiated with a parent. |
Returns
Type | Description |
---|---|
AsyncOperationHandle<GameObject> |
Instantiate(Vector3, Quaternion, Transform)
InstantiateAsync the referenced asset as type TObject.
Declaration
[Obsolete]
public AsyncOperationHandle<GameObject> Instantiate(Vector3 position, Quaternion rotation, Transform parent = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Position of the instantiated object. |
Quaternion | rotation | Rotation of the instantiated object. |
Transform | parent | The parent of the instantiated object. |
Returns
Type | Description |
---|---|
AsyncOperationHandle<GameObject> |
InstantiateAsync(Transform, Boolean)
InstantiateAsync the referenced asset as type TObject.
Declaration
public virtual AsyncOperationHandle<GameObject> InstantiateAsync(Transform parent = null, bool instantiateInWorldSpace = false)
Parameters
Type | Name | Description |
---|---|---|
Transform | parent | The parent of the instantiated object. |
Boolean | instantiateInWorldSpace | Option to retain world space when instantiated with a parent. |
Returns
Type | Description |
---|---|
AsyncOperationHandle<GameObject> |
InstantiateAsync(Vector3, Quaternion, Transform)
InstantiateAsync the referenced asset as type TObject.
Declaration
public virtual AsyncOperationHandle<GameObject> InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Position of the instantiated object. |
Quaternion | rotation | Rotation of the instantiated object. |
Transform | parent | The parent of the instantiated object. |
Returns
Type | Description |
---|---|
AsyncOperationHandle<GameObject> |
IsValid()
Returns the state of the internal operation.
Declaration
public bool IsValid()
Returns
Type | Description |
---|---|
Boolean | True if the operation is valid. |
LoadAsset<TObject>()
Load the referenced asset as type TObject.
Declaration
[Obsolete]
public AsyncOperationHandle<TObject> LoadAsset<TObject>()
Returns
Type | Description |
---|---|
AsyncOperationHandle<TObject> | The load operation. |
Type Parameters
Name | Description |
---|---|
TObject | The object type. |
LoadAssetAsync<TObject>()
Load the referenced asset as type TObject.
Declaration
public virtual AsyncOperationHandle<TObject> LoadAssetAsync<TObject>()
Returns
Type | Description |
---|---|
AsyncOperationHandle<TObject> | The load operation. |
Type Parameters
Name | Description |
---|---|
TObject | The object type. |
LoadScene()
Loads the reference as a scene.
Declaration
[Obsolete]
public AsyncOperationHandle<SceneInstance> LoadScene()
Returns
Type | Description |
---|---|
AsyncOperationHandle<SceneInstance> | The operation handle for the scene load. |
LoadSceneAsync(LoadSceneMode, Boolean, Int32)
Loads the reference as a scene.
Declaration
public virtual AsyncOperationHandle<SceneInstance> LoadSceneAsync(LoadSceneMode loadMode = null, bool activateOnLoad = true, int priority = 100)
Parameters
Type | Name | Description |
---|---|---|
LoadSceneMode | loadMode | Scene load mode. |
Boolean | activateOnLoad | If false, the scene will load but not activate (for background loading). The SceneInstance returned has an Activate() method that can be called to do this at a later point. |
Int32 | priority | Async operation priority for scene loading. |
Returns
Type | Description |
---|---|
AsyncOperationHandle<SceneInstance> | The operation handle for the request. |
ReleaseAsset()
Release the internal operation handle.
Declaration
public virtual void ReleaseAsset()
ReleaseInstance(GameObject)
Release an instantiated object.
Declaration
public virtual void ReleaseInstance(GameObject obj)
Parameters
Type | Name | Description |
---|---|---|
GameObject | obj | The object to release. |
RuntimeKeyIsValid()
Checks if the current RuntimeKey is valid.
Declaration
public virtual bool RuntimeKeyIsValid()
Returns
Type | Description |
---|---|
Boolean | Whether the RuntimeKey is valid or not. |
Implements
ToString()
String representation of asset reference.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The asset guid as a string. |
Overrides
UnLoadScene()
Unloads the reference as a scene.
Declaration
public virtual AsyncOperationHandle<SceneInstance> UnLoadScene()
Returns
Type | Description |
---|---|
AsyncOperationHandle<SceneInstance> | The operation handle for the scene load. |
ValidateAsset(Object)
Validates that the referenced asset allowable for this asset reference.
Declaration
public virtual bool ValidateAsset(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The Object to validate. |
Returns
Type | Description |
---|---|
Boolean | Whether the referenced asset is valid. |
ValidateAsset(String)
Validates that the referenced asset allowable for this asset reference.
Declaration
public virtual bool ValidateAsset(string path)
Parameters
Type | Name | Description |
---|---|---|
String | path | The path to the asset in question. |
Returns
Type | Description |
---|---|
Boolean | Whether the referenced asset is valid. |