Skip to main content
Version: v3

Loading Method

Important Attention Reminder

Coding Style wiki


Loading via Resources

Reminder When using Resources loading, no additional configuration is required. Simply place the assets under the Resources folder and load them directly by using the res# prefix followed by the asset path.

Important Using the res# prefix will switch to the Resources loading method.

// res# prefix
AssetLoaders.LoadAssetAsync<GameObject>("res#MyPrefabs/Cube");

Loading via AssetBundle

Step 1.

You must first configure it through the YooAsset Collector.

Attention Pay attention to the addressable names — in the example image, the DefaultPackage includes an addressable named Cube.

Step 2.

Additionally, when developing with AssetBundles, PatchLauncher is required for Runtime configuration. This is primarily to initialize the relevant settings needed for AssetBundle loading.

Attention Drag it into the Hierarchy window after importing.

Step 3.

Configure the Preset Packages, which will be initialized at Runtime.

  • Preset App Packages。
    • Reminder The first element will be the Default Package.
  • Preset DLC Packages.

Important The Preset Packages will be managed and checked by the main downloader, so Packages not included in the Presets must be initialized manually through the API, as described below.

Manually Initialize App Package

// [Load asset and download from specific package (Export App Bundles for CDN)]

AppPackageInfoWithBuild packageInfo = new AppPackageInfoWithBuild()
{
buildMode = BundleConfig.BuildMode.ScriptableBuildPipeline,
packageName = "OtherPackage"
};

// updatePackage = true (Will update the Manifest)
bool isInitialized = await AssetPatcher.InitAppPackage(packageInfo, true);
if (isInitialized)
await AssetLoaders.LoadAssetAsync<GameObject>("OtherPackage", "assetName");

Manually Initialize DLC Package

// [Load asset and download from specific package (Export Individual DLC Bundles for CDN)]

DlcPackageInfoWithBuild packageInfo = new DlcPackageInfoWithBuild()
{
buildMode = BundleConfig.BuildMode.ScriptableBuildPipeline,
packageName = "DlcPackage",
dlcVersion = "dlcVersion",
withoutPlatform = false
};

// updatePackage = true (Will update the Manifest)
bool isInitialized = await AssetPatcher.InitDlcPackage(packageInfo, true);
if (isInitialized)
await AssetLoaders.LoadAssetAsync<GameObject>("DlcPackage", "assetName");

Attention Distinguish between App Packages and DLC Packages, noting the different paths.

  • App Packages
    • The path follows the main program version (.../CDN/<ProductName>/<Platform>/<AppVersion>/<PackageName>).
    • Manual initialization of AssetPatcher.InitAppPackage is required (if updatePackage = false, you will need to manually call AssetPatcher.UpdatePackage to update the Manifest).
  • DLC Packages
    • The path includes the platform (.../CDN/<ProductName>/<Platform>/DLC/<PackageName>/<DlcVersion>).
    • The path does not include the platform (.../CDN/<ProductName>/DLC/<PackageName>/<DlcVersion>), which is a shared resource for all platforms.
    • Supports downloading specific versions of DLC packages and DLC package uninstallation. You must manually call AssetPatcher.InitDlcPackage and specify a specific dlcVersion. The dlcVersion can also be set to a fixed version (e.g., "latest"), so whenever the DLC is updated, you can use a fixed path for the update.

API reference:

/// <summary>
/// Init app package (If PlayMode is HostMode will request from default host path)
/// </summary>
/// <param name="packageInfo"></param>
/// <param name="updatePackage"></param>
/// <returns></returns>
public static async UniTask<bool> InitAppPackage(AppPackageInfoWithBuild packageInfo, bool updatePackage = false)

/// <summary>
/// Init dlc package (If PlayMode is HostMode will request from default host dlc path)
/// </summary>
/// <param name="packageInfo"></param>
/// <param name="updatePackage"></param>
/// <returns></returns>
public static async UniTask<bool> InitDlcPackage(DlcPackageInfoWithBuild packageInfo, bool updatePackage = false)

/// <summary>
/// Update package version and manifest by package name
/// </summary>
/// <param name="packageName"></param>
/// <returns></returns>
public static async UniTask<bool> UpdatePackage(string packageName)

Attention Additionally, the PlayMode descriptions are as follows:

  • Editor Simulate Mode (Development Mode).
  • Offline Mode (Local Mode).
  • Host Mode (Online Mode).
  • Weak Host Mode (Weak Online Mode).
  • WebGL Mode (WebGL Mode - Requesting from StreamingAssets).
  • WebGL Remote Mode (WebGL Online Mode - Requesting from StreamingAssets and other CDNs).
  • Custom Mode (Custom Mode for Mini-games)

Important Build Macro Definitions

Step 4.

After completing the prerequisites, poll the initialization state AssetPatcher.IsInitialized() == true. You can then start loading built-in assets, as follows.

Load the object with the addressable name "Cube" from the DefaultPackage.

private IEnumerator Start()
{
// Wait Until IsInitialized
while (!AssetPatcher.IsInitialized())
yield return null;

// Load asset with assign a package (from Built-in)
AssetLoaders.LoadAssetAsync<GameObject>("DefaultPackage", "Cube");
}

Important For detailed update procedures, it is recommended to refer to BundleDemo (import via Package Manager).

Attention Additionally, the sequence of the process is as follows:

  • Poll the initialization state AssetPatcher.IsInitialized() == true -> then you can load built-in resources and perform update checks.
  • Perform update check AssetPatcher.Check() -> Poll the completion state AssetPatcher.IsDone() == true -> After the update is completed -> you can load updated resources.