UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

assets

[Addressables] Resolve Bee Errors: Proper Asset Cleanup Before Build

Solution

addressablesasset pipelinememory managementeditor scripting

Unity 2019.x - Unity 6.3.x

Published Tue, Mar 17

Issue

 Deleting Addressables assets during the IPreprocessBuildWithReport.OnPreprocessBuild callback results in build failures. The Bee build system in Unity 6 performs file existence checks before this phase. Removing assets during the build loop causes the pipeline to report missing files in Library/Bee/artifacts/AppPkg because the source files are already locked for the packaging process.

Explanation

Addressables assets are indexed and copied by the Bee build system early in the compilation process. Attempting to delete assets within OnPreprocessBuild triggers a failure because the pipeline expects all assets registered in the AssetDatabase and AddressableAssetSettings to be physically present.

To resolve this, asset manipulation must be performed via a custom build entry point. This ensures the Addressables manifest and the project AssetDatabase are synchronized before the internal build engine initializes.

  1. Implement a static build method in your script that handles asset filtering.
  2. Remove the specific Addressables assets or groups using AssetDatabase.MoveAssetToTrash.
  3. Invoke AssetDatabase.SaveAssets and AssetDatabase.Refresh to finalize the project state.
  4. Call AddressableAssetSettings.BuildPlayerContent followed by BuildPipeline.BuildPlayer to finish the Addressables process.

Additional Tips

  • Consider using Addressables Labels to filter content rather than physical deletion for faster iteration.
  • Verify that your Addressables settings have Build Remote Catalog enabled if deleting local content for remote hosting.

TL;DR

To remove Addressables assets without build errors, ensure deletion occurs via a custom static build method before the BuildPlayer command is invoked, bypassing the early Bee existence check.


Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.