# TEngine AssetBundle Packaging Workflow with YooAsset: Automated Pipeline Guide

> Learn TEngine's AssetBundle packaging workflow with YooAsset. Automate your build pipeline with this configurable 7-stage editor workflow for efficient game asset management.

- Repository: [ALEX/tengine](https://github.com/alex-rachel/tengine)
- Tags: how-to-guide
- Published: 2026-02-24

---

**TEngine automates AssetBundle packaging through YooAsset by orchestrating command-line arguments, pipeline selection, and post-build file operations in a configurable 7-stage editor workflow.**

The `alex-rachel/tengine` repository provides a sophisticated **AssetBundle** packaging system that leverages the **YooAsset** framework to automate bundle creation, dependency resolution, and runtime deployment through the **TEngine AssetBundle packaging workflow with YooAsset**. This architecture enables developers to generate platform-specific bundles via Unity Editor menus or headless CI pipelines while maintaining precise control over compression algorithms, encryption schemes, and versioning strategies.

## Entry Points: Editor Menu and Command-Line Execution

The workflow exposes two primary invocation methods defined in [`UnityProject/Assets/TEngine/Editor/ReleaseTools/ReleaseTools.cs`](https://github.com/alex-rachel/tengine/blob/main/UnityProject/Assets/TEngine/Editor/ReleaseTools/ReleaseTools.cs).

For interactive editor use, the `[MenuItem("TEngine/Build/一键打包AssetBundle _F8")]` attribute (lines 60–68) exposes a keyboard-shortcut menu item that triggers `BuildCurrentPlatformAB()`. This method automatically resolves the active **BuildTarget** and initiates the pipeline.

For automated CI/CD environments, the static method `ReleaseTools.BuildAssetBundle()` serves as the headless entry point. It accepts arguments via Unity’s `-customArgument` CLI flags:

```bash
/path/to/Unity -batchmode -quit \
  -projectPath /path/to/TEngine/UnityProject \
  -executeMethod TEngine.ReleaseTools.BuildAssetBundle \
  -customArgument platform=Android \
  -customArgument outputRoot=/tmp/Builds/Android \
  -customArgument packageVersion=2024.02.24

```

## Anatomy of the Build Pipeline

The `BuildAssetBundle()` method orchestrates a 6-stage pipeline that transforms raw assets into deployable bundles.

### Stage 1: Parameter Collection and Validation

At lines 32–55 of [`ReleaseTools.cs`](https://github.com/alex-rachel/tengine/blob/main/ReleaseTools.cs), the method `CommandLineReader.GetCustomArgument` extracts three critical parameters: `outputRoot`, `packageVersion`, and `platform`. If any parameter is null or empty, the method aborts with a descriptive error, preventing invalid builds from contaminating the output directory.

### Stage 2: Platform Target Resolution

The private `GetBuildTarget(platform)` method (lines 43–75) converts the string argument (e.g., `"Android"`, `"iOS"`, `"Windows"`) into a Unity `BuildTarget` enum. This ensures the subsequent pipeline targets the correct platform-specific asset importer settings.

### Stage 3: Pipeline Selection Strategy

The `BuildInternal()` method (lines 185–207) selects the build architecture based on the `EBuildPipeline` enum. By default, **ScriptableBuildPipeline** is selected, but developers can opt for **BuiltinBuildPipeline** to use Unity’s legacy `BuildPipeline.BuildAssetBundles`. The code instantiates either `ScriptableBuildParameters` or `BuiltinBuildParameters` accordingly.

### Stage 4: BuildParameters Configuration

Between lines 213–229, the system populates a `BuildParameters` instance with production settings:

- **Output Roots**: `BuildOutputRoot` (from CLI `outputRoot`) and `BuildinFileRoot` (from `AssetBundleBuilderHelper.GetStreamingAssetsRoot()`)
- **Compression**: `ECompressOption.LZ4` for fast decompression
- **Naming Convention**: `BundleName_HashName` to prevent cache collisions
- **Share-Pack Rule**: `EnableSharePackRule = true` to optimize dependency bundling
- **Incremental Build Flags**: `ClearBuildCacheFiles = false` and `UseAssetDependencyDB = true` to enable smart caching
- **Encryption**: Optional encryption services retrieved via `GetEncryptionFromResourceModuleDriver`

### Stage 5: YooAsset Pipeline Execution

The selected pipeline executes via `pipeline.Run(buildParameters, true)` (lines 230–239). This call triggers YooAsset’s internal dependency graph resolution, applies the **SharePackRule** to eliminate redundant assets, generates binary manifest files, and writes the final `.bundle` files to `BuildOutputRoot`. The boolean parameter enables verbose logging, outputting `构建成功` (build success) or `构建失败` (build failure) to the Unity console.

### Stage 6: Post-Build StreamingAssets Deployment

Upon successful completion, `CopyStreamingAssetsFiles()` (lines 73–141) performs file operations. It retrieves the final destination address from `Settings.UpdateSetting.GetBuildAddress()`, clears existing files in that directory to prevent stale asset accumulation, and copies the generated bundles plus their manifest files from the transient build directory into the runtime **StreamingAssets** folder.

## Pipeline Architectures: Scriptable vs Built-in

**ScriptableBuildPipeline** (default) utilizes YooAsset’s custom dependency resolution and bundle layout algorithms, offering granular control over chunking and encryption. It requires the `ScriptableBuildParameters` class configuration.

**BuiltinBuildPipeline** delegates directly to Unity’s native `BuildPipeline.BuildAssetBundles`, configured through `BuiltinBuildParameters`. This mode sacrifices some advanced YooAsset optimizations for compatibility with legacy Unity workflows.

Both pipelines consume the same `BuildParameters` base class, ensuring consistent versioning and output directory structures regardless of the selected backend.

## CI/CD Automation and Encryption Integration

The workflow supports non-interactive automation through the `BuildAssetBundle()` static method. When running in batch mode, the system relies entirely on CLI arguments passed via `-customArgument`, making it compatible with Jenkins, GitHub Actions, or Unity Cloud Build. The optional encryption step (configured in Stage 4) allows the pipeline to inject custom `IEncryptionServices` implementations without modifying the core build logic, securing bundles for runtime verification.

## Summary

- **TEngine** uses **YooAsset** to automate AssetBundle creation through a 6-stage pipeline defined in [`ReleaseTools.cs`](https://github.com/alex-rachel/tengine/blob/main/ReleaseTools.cs).
- The workflow supports both Editor menu triggers (`BuildCurrentPlatformAB`) and CLI automation (`BuildAssetBundle`).
- **ScriptableBuildPipeline** is the default architecture, with **BuiltinBuildPipeline** available for legacy compatibility.
- Key configuration includes **LZ4 compression**, **SharePackRule** dependency optimization, and incremental build caching via `UseAssetDependencyDB`.
- Post-build operations automatically migrate bundles to the **StreamingAssets** directory defined in `Settings.UpdateSetting`.
- Optional encryption integrates at the `BuildParameters` level through `GetEncryptionFromResourceModuleDriver`.

## Frequently Asked Questions

### How do I trigger the TEngine AssetBundle build from a CI pipeline?

Invoke Unity in batchmode with `-executeMethod TEngine.ReleaseTools.BuildAssetBundle` and pass parameters using `-customArgument platform=Android outputRoot=/path packageVersion=1.0`. The method parses these arguments at lines 32–55 of [`ReleaseTools.cs`](https://github.com/alex-rachel/tengine/blob/main/ReleaseTools.cs) and aborts if required fields are missing.

### What is the difference between ScriptableBuildPipeline and BuiltinBuildPipeline in TEngine?

**ScriptableBuildPipeline** (default) uses YooAsset’s custom dependency resolution and supports advanced features like **SharePackRule**, while **BuiltinBuildPipeline** wraps Unity’s native `BuildPipeline.BuildAssetBundles` for legacy compatibility. The selection occurs at lines 185–207 in [`ReleaseTools.cs`](https://github.com/alex-rachel/tengine/blob/main/ReleaseTools.cs) based on the `EBuildPipeline` enum.

### Where does TEngine output the final AssetBundle files after a successful build?

Bundles are initially written to the `outputRoot` CLI argument, then copied to the path returned by `Settings.UpdateSetting.GetBuildAddress()` via `CopyStreamingAssetsFiles()` (lines 73–141). The transient build directory is rooted at `AssetBundleBuilderHelper.GetStreamingAssetsRoot()`.

### How does TEngine handle encryption during the AssetBundle packaging process?

At lines 213–229, the pipeline checks `GetEncryptionFromResourceModuleDriver()` to retrieve an optional `IEncryptionServices` instance. If present, this service is injected into the `BuildParameters`, causing YooAsset to encrypt bundle headers or data during the `pipeline.Run()` execution (lines 230–239).