docs.unity3d.com
Search Results for

    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. To determine if the reference is set, use RuntimeKeyIsValid().

    Inheritance
    object
    AssetReference
    AssetReferenceT<TObject>
    Implements
    IKeyEvaluator
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: UnityEngine.AddressableAssets
    Assembly: solution.dll
    Syntax
    [Serializable]
    public class AssetReference : IKeyEvaluator

    Constructors

    Name Description
    AssetReference()

    Construct a new AssetReference object.

    AssetReference(string)

    Construct a new AssetReference object.

    Fields

    Name Description
    m_AssetGUID

    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.

    AssetGUID

    Stores the guid of the asset.

    IsDone

    Get the loading status of the internal operation.

    OperationHandle

    The AsyncOperationHandle currently being used by the AssetReference. For example, if you call AssetReference.LoadAssetAsync, this property will return a handle to that operation.

    RuntimeKey

    The actual key used to request the asset at runtime. RuntimeKeyIsValid() can be used to determine if this reference was set.

    SubObjectGUID

    Stores the guid of the sub object (if available).

    SubObjectName

    Stores the name of the sub object.

    Methods

    Name Description
    InstantiateAsync(Transform, bool)

    InstantiateAsync the referenced asset as type TObject. This cannot be used a second time until the first load is released. If you wish to call load multiple times on an AssetReference, use Addressables.InstantiateAsync() and pass your AssetReference in as the key. See the Loading Addressable Assets documentation for more details.

    InstantiateAsync(Vector3, Quaternion, Transform)

    InstantiateAsync the referenced asset as type TObject. This cannot be used a second time until the first load is released. If you wish to call load multiple times on an AssetReference, use Addressables.InstantiateAsync() and pass your AssetReference in as the key. See the Loading Addressable Assets documentation for more details.

    IsValid()

    Returns the state of the internal operation.

    LoadAssetAsync<TObject>()

    Load the referenced asset as type TObject. This cannot be used a second time until the first load is released. If you wish to call load multiple times on an AssetReference, use LoadAssetAsync<TObject>(object) and pass your AssetReference in as the key.

    See the Loading Addressable Assets documentation for more details.

    LoadSceneAsync(LoadSceneMode, bool, int)

    Loads the reference as a scene. This cannot be used a second time until the first load is unloaded. If you wish to call load multiple times on an AssetReference, use Addressables.LoadSceneAsync() and pass your AssetReference in as the key. See the Loading Addressable Assets documentation for more details.

    ReleaseAsset()

    Release the internal operation handle.

    ReleaseInstance(GameObject)

    Release an instantiated object.

    RuntimeKeyIsValid()

    Checks if the current RuntimeKey is valid.

    ToString()

    String representation of asset reference.

    UnLoadScene()

    Unloads the reference as a scene.

    ValidateAsset(string)

    Validates that the referenced asset allowable for this asset reference.

    ValidateAsset(Object)

    Validates that the referenced asset allowable for this asset reference.


    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Constructors
    • Fields
    • Properties
    • Methods
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)