Version: 1.7
LanguageEnglish
  • C#

InstantAssetEditorUtility.BuildAssetPacker

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 static bool BuildAssetPacker(string pathName, string[] directories, int size, BuildTarget targetPlatform);

Parameters

pathName The path of folder to save InstantAssetTable file and bundles.
directories The paths of folders where assets packing operation is performed.
size Size per bundle in bytes.
targetPlatform The target platform for asset packing.

Returns

bool Return true if asset packing is successful, return false if it fails.

Description

Pakcing assets from the specified folders to some bundles, and generate an InstantAssetTable to record asset information.

InstantAssetTable is saved in a single file with a name based on the folder path(e.g., InstantAssetTable_Assets_Test for assets in Assets/Test).

using UnityEditor;
using UnityEngine;

public class BasicBuildExample { [MenuItem("Tools/Build Instant Assets/Basic Directory Build")] public static void BuildAssetsFromDirectories() { string outputPath = "Assets/Output/InstantAssets"; string[] directories = { "Assets/Resources/UI", "Assets/Resources/Models" }; int maxBundleSize = 1024 * 1024; // 1MB per bundle bool success = InstantAssetEditorUtility.BuildAssetPacker( outputPath, directories, maxBundleSize, BuildTarget.StandaloneWindows64);

if (success) { Debug.Log("Instant Asset packages built successfully!"); } else { Debug.LogError("Failed to build Instant Asset packages."); } } }

Declaration

public static bool BuildAssetPacker(string pathName, InstantAssetAliasTable[] instantAssetAliasTables, InstantAssetOptions buildOptions, int size, BuildTarget targetPlatform);

Parameters

pathName The path of folder to save InstantAssetTable file and bundles.
size Size per bundle in bytes.
targetPlatform The target platform for asset packing.
instantAssetAliasTables Array of alias tables specifying directories or specific assets.
buildOptions Build options (compression method, rebuild behavior, etc.).

Returns

bool Return true if asset packing is successful, return false if it fails.

Description

Provides fine-grained control over the asset packing process, allowing custom alias table names, specific asset lists, and build options including compression settings.

using UnityEditor;
using UnityEngine;

public class AdvancedBuildExample { [MenuItem("Tools/Build Instant Assets/Advanced Custom Build")] public static void BuildAssetsAdvanced() { string outputPath = "Assets/Output/CustomInstantAssets";

var aliasTables = new[] { new InstantAssetAliasTable { aliasTableName = "UITable", buildDirectoryPath = "Assets/Resources/UI" }, new InstantAssetAliasTable { aliasTableName = "CharacterModels", assetNames = new[] { "Assets/Models/Player.fbx", "Assets/Models/NPC.fbx" } } };

var options = InstantAssetOptions.CompressionLz4HC | InstantAssetOptions.ForceRebuild; int maxBundleSize = 2 * 1024 * 1024; // 2MB per bundle

bool success = InstantAssetEditorUtility.BuildAssetPacker( outputPath, aliasTables, options, maxBundleSize, BuildTarget.Android);

if (success) { Debug.Log("Advanced Instant Asset packages built successfully!"); } else { Debug.LogError("Failed to build advanced Instant Asset packages."); } } }