docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Property InstanceProvider

    InstanceProvider

    The Instance Provider used by the Addressables System.

    Declaration
    public static IInstanceProvider InstanceProvider { get; }
    Property Value
    Type Description
    IInstanceProvider

    The IInstanceProvider object used to create instances of GameObjects.

    Remarks

    Retrieves the interface used by the Addressables Asset System to create instances of Addressable GameObjects.

    Examples

    The example below instantiates a GameObject using ProvideInstance.

    public AssetReferenceGameObject asset; // Identify the asset
    AsyncOperationHandle<GameObject> instHandle;
    AsyncOperationHandle<IList<IResourceLocation>> locHandle;
    

    void UsingInstanceProviderSample() { locHandle = Addressables.LoadResourceLocationsAsync(asset, typeof(GameObject)); locHandle.Completed += OnLoadComplete; }

    void OnLoadComplete(AsyncOperationHandle<IList<IResourceLocation>> handle) { if (handle.Status == AsyncOperationStatus.Succeeded) { Debug.Log($"Successfully loaded resource locations"); foreach (IResourceLocation location in handle.Result) { ResourceManager rm = Addressables.ResourceManager; IInstanceProvider provider = Addressables.InstanceProvider; instHandle = rm.ProvideInstance(provider, location, default(InstantiationParameters)); instHandle.Completed += OnProvideInstanceComplete; } } }

    void OnProvideInstanceComplete(AsyncOperationHandle<GameObject> handle) { if (handle.Status == AsyncOperationStatus.Succeeded) { Debug.Log($"Successfully instantiated GameObject named ''"); } }

    void ReleaseResources() { locHandle.Release(); instHandle.Release(); }

    // When ready to release the asset, call ReleaseResources(). // For example during OnDestroy(). // void OnDestroy() // { // ReleaseResources(); // }

    In This Article
    Back to top
    Copyright © 2025 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)