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.
Inheritance
Inherited Members
Namespace: UnityEngine.AddressableAssets
Syntax
[Serializable]
public class AssetReference
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 |
---|---|---|
System.String | guid | The guid of the asset. |
Properties
RuntimeKey
The actual key used to request the asset at runtime.
Declaration
public Hash128 RuntimeKey { get; }
Property Value
Type | Description |
---|---|
Hash128 |
Methods
Instantiate<TObject>(Transform, Boolean)
Instantiate the referenced asset as type TObject.
Declaration
public IAsyncOperation<TObject> Instantiate<TObject>(Transform parent = null, bool instantiateInWorldSpace = false)
Parameters
Type | Name | Description |
---|---|---|
Transform | parent | The parent of the instantiated object. |
System.Boolean | instantiateInWorldSpace | Option to retain world space when instantiated with a parent. |
Returns
Type | Description |
---|---|
IAsyncOperation<TObject> |
Type Parameters
Name | Description |
---|---|
TObject | The object type. |
Instantiate<TObject>(Vector3, Quaternion, Transform)
Instantiate the referenced asset as type TObject.
Declaration
public IAsyncOperation<TObject> Instantiate<TObject>(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 |
---|---|
IAsyncOperation<TObject> |
Type Parameters
Name | Description |
---|---|
TObject | The object type. |
LoadAsset<TObject>()
Load the referenced asset as type TObject.
Declaration
public IAsyncOperation<TObject> LoadAsset<TObject>()
Returns
Type | Description |
---|---|
IAsyncOperation<TObject> | The load operation. |
Type Parameters
Name | Description |
---|---|
TObject | The object type. |
ReleaseAsset<TObject>(TObject)
Release the refrerenced asset.
Declaration
public void ReleaseAsset<TObject>(TObject obj)
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | The object to release. |
Type Parameters
Name | Description |
---|---|
TObject | The object type. |
ReleaseInstance<TObject>(TObject)
Release an instantiated object.
Declaration
public void ReleaseInstance<TObject>(TObject obj)
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | The object to release. |
Type Parameters
Name | Description |
---|---|
TObject | The object type. |
ToString()
String representation of asset reference.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | The asset guid as a string. |
Overrides
ValidateType(Type)
Validates that the referenced asset is the correct type.
Declaration
public virtual bool ValidateType(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to validate. |
Returns
Type | Description |
---|---|
System.Boolean | Whether the referenced asset is the specified type. |