Version: 1.6
LanguageEnglish
  • C#

AssetBundle.InstantiateAsync

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public AssetBundleRequest InstantiateAsync(string name);

Parameters

name Corresponding resource name in assetbundle.

Returns

AssetBundleRequest Asynchronous load request from an AssetBundle.

Description

Allow the user to implement asynchronous instantiation.

using UnityEngine;
using System.Collections;
using System.IO;

public class Example : MonoBehaviour { AssetBundle myLoadedAssetBundle;

void Start() { //load Assetbundle myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "myassetBundle")); if (myLoadedAssetBundle == null) { Debug.Log("Failed to load AssetBundle!"); return; } // Use a coroutine to Instantiate in the background StartCoroutine(InstantiateAsyc()); } IEnumerator InstantiateAsyc() { yield return myLoadedAssetBundle.InstantiateAsync(myLoadedAssetBundle.GetAllAssetNames()[0]); }

}