Skip to content

Exporter Forces Unnecessary REPO Assets to be Included in Asset Bundles #15

@Ardot66

Description

@Ardot66

This is my first time using the REPOLib SDK, so please correct me if I'm wrong. From what I can tell, any assets from REPO that are referenced by my package are automatically included in the bundle. As you can see, almost all of the assets in the image below are directly part of REPO.

Image

This can lead to serious bloat, as especially sounds, textures, and meshes quickly bloat bundles. In my case, I just referenced a couple sounds and my bundle went from ~20kb to ~400kb. I imagine this could get especially problematic if many mods are all including the same REPO assets, causing the game to slow down as it has to handle many instances of the same asset being loaded in to memory.

I did look into why this is happening, and it looks like it's the fault of this function in PackageExporter:

public static IEnumerable<(string Path, bool IsDependency)> FindContents(Mod mod)
{
    string modPath = AssetDatabase.GetAssetPath(mod);
    string directory = Path.GetDirectoryName(modPath);
    string[] content = AssetDatabase.FindAssets("t:Content", new[] { directory })
        .Select(AssetDatabase.GUIDToAssetPath)
        .ToArray();
    
    foreach (string asset in content)
    {
        yield return (asset, false);
    }

    string[] dependencies = AssetDatabase.GetDependencies(content);
    foreach (string dependency in dependencies)
    {
        yield return (dependency, true);
    }
}

And more specifically, this line:

string[] dependencies = AssetDatabase.GetDependencies(content);

According to the Unity Scripting API docs, AssetDatabase.GetDependencies returns ALL assets that are referenced by the input assets, even if they are not necessarily required for the build process. (See this page)

As far as I can tell, the fix should just be as simple as ignoring assets that are under the Assets/REPO/Game folder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions