Class AssetReference | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    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
    System.Object
    AssetReference
    AssetReferenceT<TObject>
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    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

    Asset

    The loaded asset. This value is only set after the IAsyncOperation returned from LoadAsset completes. It will not be set if only Instantiate is called. It will be set to null if release is called.

    Declaration
    public Object Asset { get; }
    Property Value
    Type Description
    Object

    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)where TObject : Object
    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)where TObject : Object
    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>()where TObject : Object
    Returns
    Type Description
    IAsyncOperation<TObject>

    The load operation.

    Type Parameters
    Name Description
    TObject

    The object type.

    ReleaseAsset<TObject>()

    Release the refrerenced asset.

    Declaration
    public void ReleaseAsset<TObject>()where TObject : Object
    Type Parameters
    Name Description
    TObject

    The object type.

    ReleaseAsset<TObject>(Object)

    Release the refrerenced asset.

    Declaration
    [Obsolete("Use ReleaseAsset without parameters.  It will release the asset loaded via LoadAsset.")]
    public void ReleaseAsset<TObject>(Object asset)where TObject : Object
    Parameters
    Type Name Description
    Object asset
    Type Parameters
    Name Description
    TObject

    The object type.

    ReleaseInstance<TObject>(TObject)

    Release an instantiated object.

    Declaration
    public void ReleaseInstance<TObject>(TObject obj)where TObject : Object
    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
    System.Object.ToString()

    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.

    In This Article
    • Constructors
      • AssetReference()
      • AssetReference(String)
    • Properties
      • Asset
      • RuntimeKey
    • Methods
      • Instantiate<TObject>(Transform, Boolean)
      • Instantiate<TObject>(Vector3, Quaternion, Transform)
      • LoadAsset<TObject>()
      • ReleaseAsset<TObject>()
      • ReleaseAsset<TObject>(Object)
      • ReleaseInstance<TObject>(TObject)
      • ToString()
      • ValidateType(Type)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023