How TEngine Integrates with YooAsset's Asset Streaming System

TEngine integrates with YooAsset's asset streaming system by implementing the ResourceModule as a thin abstraction layer that delegates all asset operations—initialization, package management, synchronous loads, asynchronous streaming, and remote download checks—directly to YooAsset's native API while adding engine-specific logging and error handling.

The alex-rachel/tengine repository demonstrates a production-ready integration pattern where TEngine treats YooAsset as its foundational resource engine. This architecture allows developers to leverage YooAsset's advanced streaming capabilities through a simplified, high-level interface that maintains clean separation between the engine's core systems and third-party asset management logic.

Core Integration Architecture

At the heart of the integration lies the ResourceModule, located in UnityProject/Assets/TEngine/Runtime/Module/ResourceModule/ResourceModule.cs. This module functions as a facade that translates TEngine's resource requests into YooAsset operations. Rather than implementing custom asset streaming logic, TEngine wraps YooAsset's existing primitives, ensuring compatibility with the library's update cycle while providing a unified API for scene loading, asset referencing, and bundle management.

The integration follows a delegation pattern where TEngine handles high-level lifecycle management—such as module initialization and shutdown—while YooAsset manages the low-level details of asset decompression, dependency resolution, and memory streaming.

Initialization and Package Management

TEngine configures YooAsset during its startup sequence by invoking initialization routines that establish logging and operational parameters.

In ResourceModule.cs at lines L122-L123, TEngine initializes the YooAsset runtime with a custom logger and sets performance constraints:

  • YooAssets.Initialize(new ResourceLogger()) – Attaches TEngine's logging implementation to capture all YooAsset diagnostic output
  • YooAssets.SetOperationSystemMaxTimeSlice(Milliseconds) – Configures the maximum time slice for the operation system to prevent frame rate drops during heavy loading

Following initialization, TEngine manages package creation at lines L127-L131. The system attempts to retrieve an existing package using YooAssets.TryGetPackage(packageName), creates a new instance via YooAssets.CreatePackage(packageName) if absent, and designates it as the default package through YooAssets.SetDefaultPackage(defaultPackage). This ensures that all subsequent load operations target the correct asset container without requiring explicit package references in every call.

Asset Loading Mechanisms

TEngine exposes multiple loading strategies through the ResourceModule, each mapping directly to YooAsset's streaming capabilities.

Synchronous Asset Loading

For immediate asset retrieval, TEngine calls YooAssets.LoadAssetSync(location, assetType) as implemented in ResourceModule.cs at lines L644-L647. The method resolves the appropriate package—typically the default package unless overridden—and returns the loaded asset object synchronously. This approach suits small, essential assets required during scene initialization where blocking behavior is acceptable.

Asynchronous Asset Loading

Non-blocking loads utilize YooAssets.LoadAssetAsync(location, assetType) at lines L667-L670. TEngine wraps the resulting AssetHandle in a Task-based API, allowing developers to await completion without blocking the main thread. This integration supports YooAsset's background streaming, enabling large assets to load while gameplay continues.

Tag-Based Batch Loading

TEngine supports bulk operations through tag filtering. At lines L499-L503, the ResourceModule queries YooAssets.GetAssetInfos(tag) to retrieve all assets matching a specific tag, then iterates through the collection to load each asset either synchronously or asynchronously. This pattern simplifies management of themed asset groups, such as loading all "UI_Skins" or "Level_1_Props" simultaneously.

Sub-Asset and Sprite Streaming

Complex asset types receive specialized handling through extension components. The ResourceExtComponent.SubSprite.cs file (lines L52-L62) demonstrates sub-asset loading for sprite atlases.

The process involves:

  1. Retrieving asset metadata via YooAssets.GetAssetInfo(location)
  2. Loading all contained sprites using YooAssets.LoadSubAssetsAsync<Sprite>(location)
  3. Awaiting the handle's completion Task to access the sprite array

This pattern enables efficient texture atlas usage while maintaining individual sprite accessibility, critical for 2D game development where atlasing reduces draw calls.

Remote Download and Streaming Checks

TEngine integrates YooAsset's remote delivery system to support downloadable content (DLC) and patch systems. Before initiating a load operation, TEngine checks whether an asset requires network retrieval.

At lines L462-L466 in ResourceModule.cs, the method YooAssets.IsNeedDownloadFromRemote(location) determines if the asset exists locally or must be fetched from a remote server. This check enables conditional UI flows, such as displaying download progress bars or connection requirement warnings.

Additionally, TEngine configures the underlying download system at line L1231 by invoking YooAssets.SetDownloadSystemUnityWebRequest(downloadSystemUnityWebRequest), switching YooAsset's networking layer to Unity's native WebRequest implementation for better platform compatibility and cookie handling.

Practical Implementation Examples

The following examples demonstrate the integration patterns used throughout TEngine's codebase:

Initializing the Resource System:

public void Init()
{
    // Initialise YooAsset with a custom logger
    YooAssets.Initialize(new ResourceLogger());

    // Limit the per‑frame operation time slice (default 10 ms)
    YooAssets.SetOperationSystemMaxTimeSlice(Milliseconds);

    // Ensure a default package exists
    var package = YooAssets.TryGetPackage(packageName) ??
                  YooAssets.CreatePackage(packageName);
    YooAssets.SetDefaultPackage(package);
}

Loading an Asset Synchronously:

public T LoadAsset<T>(string location) where T : UnityEngine.Object
{
    // Resolve the correct package (default or custom)
    var package = YooAssets.GetPackage(DefaultPackageName);
    // Load the asset synchronously via YooAsset
    return (T)YooAssets.LoadAssetSync(location, typeof(T));
}

Loading an Asset Asynchronously:

public async Task<T> LoadAssetAsync<T>(string location) where T : UnityEngine.Object
{
    var package = YooAssets.GetPackage(DefaultPackageName);
    var handle  = YooAssets.LoadAssetAsync(location, typeof(T));
    await handle.Task;                      // await YooAsset’s async handle
    return (T)handle.AssetObject;
}

Loading All Sprites from an Atlas (Sub‑Asset):

public async Task<Sprite[]> LoadSpritesAsync(string location)
{
    // Obtain asset info first (needed for sub‑asset loading)
    var assetInfo = YooAssets.GetAssetInfo(location);
    // Load all sprites contained in the same asset bundle
    var handle = YooAssets.LoadSubAssetsAsync<Sprite>(location);
    await handle.Task;
    return handle.AssetObjects;
}

Checking for Remote Download Requirement:

public bool NeedsRemoteDownload(string location)
{
    return YooAssets.IsNeedDownloadFromRemote(location);
}

Summary

  • TEngine integrates with YooAsset's asset streaming system through the ResourceModule, which acts as a thin wrapper around YooAsset's native API rather than implementing custom streaming logic.
  • Initialization occurs in ResourceModule.cs (lines L122-L131) via YooAssets.Initialize() with custom logging and default package configuration.
  • Asset loading supports both sync and async patterns, with TEngine delegating directly to YooAssets.LoadAssetSync() and YooAssets.LoadAssetAsync() while managing package resolution internally.
  • Sub-asset loading for sprites is handled through extension components that call YooAssets.LoadSubAssetsAsync<T>() for efficient atlas management.
  • Remote streaming capabilities leverage YooAssets.IsNeedDownloadFromRemote() to check network requirements before loading, supporting DLC and patching workflows.

Frequently Asked Questions

What is the role of ResourceModule in TEngine's YooAsset integration?

The ResourceModule serves as the primary integration point that encapsulates all YooAsset functionality. Located at UnityProject/Assets/TEngine/Runtime/Module/ResourceModule/ResourceModule.cs, it initializes the YooAsset runtime, manages package lifecycles, and exposes high-level methods for asset loading that internally call YooAsset's API. This module allows the rest of TEngine to remain agnostic about the underlying asset system while providing centralized error handling and logging.

How does TEngine handle asynchronous asset loading with YooAsset?

TEngine utilizes YooAsset's handle-based asynchronous system by calling YooAssets.LoadAssetAsync(location, assetType) and returning the resulting AssetHandle. As shown in ResourceModule.cs at lines L667-L670, TEngine wraps these handles in Task-based APIs, enabling the use of async/await patterns throughout the engine. This approach supports background streaming without blocking the main thread, with the operation system time slice (configured at initialization) preventing frame rate drops during intensive loads.

Can TEngine load sub-assets like sprites from texture atlases using YooAsset?

Yes, TEngine supports sub-asset loading through extension components. The ResourceExtComponent.SubSprite.cs file demonstrates loading individual sprites from texture atlases by calling YooAssets.GetAssetInfo(location) followed by YooAssets.LoadSubAssetsAsync<Sprite>(location). This pattern retrieves all sprite objects packed within a single texture asset, which is essential for optimizing draw calls in 2D projects while maintaining individual sprite accessibility.

How does TEngine determine if an asset needs to be downloaded from a remote server?

Before attempting to load remote assets, TEngine checks availability using YooAssets.IsNeedDownloadFromRemote(location), as implemented in ResourceModule.cs at lines L462-L466. This method returns a boolean indicating whether the asset exists in local storage or requires network retrieval. TEngine uses this information to trigger appropriate UI flows, such as displaying download progress indicators or connection requirement dialogs, ensuring that asset streaming only occurs when necessary and with user consent.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →