Everything in a Resources folder is always built into the player. If an asset in an AssetBundle uses an asset from Resources, Unity also copies that asset into the bundle, so it's stored twice. Assigning the Resources asset to its own bundle doesn't help because the player still contains it. To avoid duplicates, move assets that bundles use out of Resources or stop bundling them.
Applies to: Unity 6.0, 6.3, and 6.6.
Why does Unity copy the asset into the bundle?
A bundle can only point to assets that are in another bundle. Assets in Resources aren't in any bundle, so Unity copies them into every bundle that needs them. That keeps the bundle working on its own, but the asset is then stored in the player and in the bundle.
How do I find duplicated assets?
This Editor script lists every asset in a Resources folder that is copied into an AssetBundle. Save it as ResourcesBundleChecker.cs in a folder named Editor, then select Tools > Check AssetBundles For Resources Assets. Results appear in the Console window.
using System.Linq;
using UnityEditor;
using UnityEngine;
public static class ResourcesBundleChecker
{
// Adds Tools > Check AssetBundles For Resources Assets to the Editor menu bar.
[MenuItem("Tools/Check AssetBundles For Resources Assets")]
public static void Check()
{
int problems = 0;
foreach (var bundle in AssetDatabase.GetAllAssetBundleNames())
{
var bundleAssets = AssetDatabase.GetAssetPathsFromAssetBundle(bundle);
// Every asset the bundle contains, directly or through dependencies
foreach (var path in AssetDatabase.GetDependencies(bundleAssets, true))
{
if (!path.Contains("/Resources/"))
continue;
// Assets assigned to a different bundle are referenced, not copied into this one
var owner = AssetDatabase.GetImplicitAssetBundleName(path);
if (!string.IsNullOrEmpty(owner) && owner != bundle)
continue;
problems++;
Debug.LogWarning($"AssetBundle '{bundle}' includes '{path}', which is in a Resources folder. " +
"It's also built into the player, so it's stored twice.");
}
}
Debug.Log($"Resources check finished: {problems} asset(s) found in both Resources and AssetBundles.");
}
}
How do I fix it?
- Run the script above to list the assets.
- For each asset that's only loaded through AssetBundles, move it out of the
Resourcesfolder. If several bundles use it, assign it to a shared AssetBundle. - For each asset that must stay in
Resources, because you load it withResources.Load, make sure nothing in your AssetBundles references it. - Rebuild your AssetBundles and run the script again.
For new projects, consider the Addressables package instead of mixing Resources and AssetBundles. It manages bundle dependencies for you.
More information
- Unity Manual: Handling dependencies between AssetBundles
- Scripting API: AssetDatabase.GetDependencies
- Unity Manual: Loading resources at runtime