In the YooAsset asset management framework, Package and Bundle are two core concepts representing different levels of asset management. Below are their definitions, differences, and typical application scenarios:
1. Package (Asset Package)
Definition
A Package is a logical unit of asset collection, typically corresponding to a complete module or functional feature (e.g., “Login Module,” “Battle Module”). A Package can contain multiple Bundles and supports independent versioning, updating, and management.
Key Features
- Modular Management: Assets are divided by function or scene, enabling on-demand loading and unloading.
- Version Control: Supports updating a specific Package individually without needing to update the entire project’s assets.
- Dependency Isolation: Asset dependencies between different Packages can be isolated to avoid redundant loading.
- Hot-Update Friendly: Ideal for dynamically downloading and replacing module assets, reducing the initial download size for players.
Typical Scenarios
- Splitting a game into a “Core Package + Sub-module Packages.” Players download the core package first and get other modules as needed.
- Updating a specific feature (like a seasonal event) without re-packaging all game assets.
2. Bundle (Asset Bundle)
Definition
A Bundle is a physical unit of asset files, which are binary files generated by the build tool (e.g., YooAsset), similar to Unity’s AssetBundle. A Bundle contains several asset files (textures, prefabs, scenes, etc.) and is the smallest unit of loading at runtime.
Key Features
- Asset Compression: Supports LZMA, LZ4, and other compression algorithms to reduce file size.
- Dependency Management: Automatically analyzes dependencies between assets to ensure integrity during loading.
- Incremental Updates: Only updates changed Bundles by comparing file hash values.
- Loading Optimization: Supports asynchronous loading and caching strategies to prevent frame drops.
Typical Scenarios
- Packaging high-frequency assets (e.g., UI Atlases) into independent Bundles to improve loading efficiency.
- Separating shared resources (e.g., Shaders, common scripts) into a “Common Bundle” to reduce duplication.
3. Relationship Between Package and Bundle
| Dimension | Package | Bundle |
| Level | Logical Layer (Module Level) | Physical Layer (File Level) |
| Function | Manages versions, updates, and dependencies | Manages file loading, compression, and storage |
| Update Granularity | By module (e.g., updating an “Event”) | By file (e.g., updating a texture or scene) |
| Dependencies | Isolates module-level dependencies | Handles internal resource cross-referencing |
| Typical Size | Large (may contain multiple Bundles) | Small (single or few assets) |
Example
Suppose a game has two modules: Core Gameplay and Spring Event.
- Package:
CorePackage: Contains character, scene, and basic UI Bundles.SpringEventPackage: Contains event scenes and limited-edition skin Bundles.
- Bundle:
characters.bundle(Character models and animations)ui_atlas.bundle(UI textures)spring_scene.bundle(Spring event specific scene)
4. Actual Workflow
Asset Division
- Logical: Divide assets into different Packages based on functionality (e.g.,
PackageA= Battle,PackageB= Story). - Physical: Within each Package, divide assets into Bundles based on type or frequency of use (e.g.,
effects.bundle= VFX assets).
Packaging and Distribution
- During the build, YooAsset generates an independent manifest and Bundle files for each Package.
- The core Package is distributed with the installation apk/ipa, while other Packages are downloaded via hot updates.
Runtime Loading
- Initialize the Package:
var package = YooAssets.GetPackage("CorePackage"); package.InitializeAsync(); - Load Assets from the Package:
var handle = package.LoadAssetAsync<GameObject("Assets/Characters/Player.prefab"); yield return handle;
GameObject player = handle.AssetObject as GameObject;
Hot Updates
When an update is detected for a specific Package, only the corresponding changed Bundle files are downloaded to replace the old versions.
5. Summary
- Package is the macro-level management unit used for modularization, version control, and distribution.
- Bundle is the micro-level loading unit used to optimize storage, loading performance, and file dependencies.
- Collaboration: A Package organizes multiple Bundles to implement flexible distribution strategies, while Bundles ensure high efficiency during runtime through fine-grained control.