Overview
This recipe shows you how to load Addressable content packages at runtime using thePackageSubsystem and IPackageService. Content packages enable downloadable or remotely updated scenarios, asset bundles, and other Addressables-driven payloads that integrate with Molca’s runtime package service. You’ll learn how to configure packages, load them asynchronously, access loaded assets, and handle loading errors.
Prerequisites
- SDK modules: Molca Core installed
- Unity setup: RuntimeManager configured, Unity Addressables package installed
- Prior knowledge: RuntimeManager, Content packages, Dependency injection
- Configuration: ContentPackageSettings configured in Global Settings
Step-by-step
Step 1: Configure content packages in your project
Set up Addressables groups and configure the ContentPackageSettings module in Global Settings.ContentPackageSettings module tells PackageSubsystem where to find remote catalogs and how to manage the download queue.
Step 2: Access PackageSubsystem after initialization
UseRuntimeManager.GetSubsystem<PackageSubsystem>() to access the package service after initialization completes.
RuntimeManager.WaitForInitialization() ensures that all RuntimeSubsystem components (including PackageSubsystem) are initialized before you access them. The PackageService property provides the IPackageService interface for loading packages.
Step 3: Load a content package asynchronously
Use theIPackageService API to queue and load content packages. Handle the async operation with proper error checking.
IPackageService manages the download queue and handles Addressables catalog loading. Using async/await prevents blocking the main thread during downloads.
Step 4: Access loaded assets from the package
Once a package is loaded, use Addressables API to instantiate or load assets by label or address.PackageSubsystem, the Addressables system knows about the assets. You can then use standard Addressables API (LoadAssetAsync, InstantiateAsync) to access them.
Step 5: Handle loading errors and retry logic
Implement error handling and retry logic for network failures or missing packages.Complete example
Here’s a complete example showing package loading with progress tracking and error handling:- Proper initialization sequence with
WaitForInitialization() - Null checks for
PackageSubsystemandPackageService - Retry logic for network failures
- Loading assets from the package using Addressables
- Dependency injection for runtime-created objects
- Cleanup in
OnDestroy
Troubleshooting
- PackageSubsystem or PackageService is null: Ensure the RuntimeManager prefab includes a
PackageSubsystemcomponent. Verify thatRuntimeManager.WaitForInitialization()completes before accessing the subsystem. Check thatContentPackageSettingsis configured in Global Settings. - Downloads never start or queue looks stuck: Confirm
ContentPackageSettingsconfiguration in Global Settings. Verify Addressables labels/paths match your configuration. Check platform build output and remote catalog URLs. Review Unity console for package-specific logs. - Wrong or missing bundle after Addressables build: Run a clean Addressables build (Clear Build Cache, then New Build). Verify remote catalog URLs and profile settings. Confirm
AddressablesBuildNotificationProviderbehavior for your Unity/Addressables version. - Content loads in Editor but not in player: Compare Addressables Play Mode Script (Fast Mode, Virtual Mode, Packed Mode) vs standalone build configuration. Verify CCD/remote hosting is accessible. Ensure initialization order awaits
WaitForInitialization()before usingPackageService. - Asset not found after package loads: Verify the asset address or label matches exactly (case-sensitive). Check that the asset is included in the Addressables group and built into the catalog. Use Addressables Event Viewer (Window → Asset Management → Addressables → Event Viewer) to debug load operations.
Related
- Content packages — detailed documentation on the content package system
- RuntimeManager — bootstrap and subsystem access
- Global Settings — ContentPackageSettings configuration
- Dependency injection — injecting dependencies into loaded content
- Recipe: Implement dependency injection — prerequisite for injecting services