Set Assets as included in asset bundles

Issue #9 closed
Matt D created an issue

As the assets aren't being set as being in asset bundles, could the tool automatically set the asset bundle names ON the asset? Otherwise, if the assets will be included in the final build.

The code for this goes something like

AssetImporter importer = AssetImporter.GetAtPath(assetPath);
importer.assetBundleName = name;

Comments (9)

  1. Sam Narain

    @DWSMatt do you mean like when you have Asset A, which normally wouldn't belong to anything, is set to Asset Bundle B on the original Asset A?

  2. Matt D reporter

    @samnarain Exactly. It's just so that these assets are not included in the actual shipped binaries and executables of the game.

  3. Hiroki Omae

    I would like to know more detail about the issue. Do you want to make sure that those assets are excluded from final build, or do you want to make sure those assets are included?

  4. Matt D reporter

    So they are excluded. Maybe make it as an option? It's just useful for people like me who are making the transition to bundles so they are visibly marked.

  5. Hiroki Omae

    Unfortunately setting assetBundleName does not exclude the asset from Player build. While assetBundleName does not provide the feature to exclude, my recommendation is to use Label to mark if the asset is already in asset bundle. With ABGT adding Postprocess script will allow you to do it. You can also set assetBundleName with Postprocess script in similar way if you really want to do that.

    using UnityEngine;
    using UnityEditor;
    
    using System;
    using System.IO;
    using System.Text;
    using System.Collections.Generic;
    
    /**
    Example code for asset bundle build postprocess.
    */
    public class LabelAssetBundleAssets : AssetBundleGraph.IPostprocess {
        /* 
         * DoPostprocess() is called when build performed.
         * @param [in] reports  collection of AssetBundleBuildReport from each BundleBuilders.
         */
        public void DoPostprocess (IEnumerable<AssetBundleGraph.AssetBundleBuildReport> buildReports, IEnumerable<AssetBundleGraph.ExportReport> exportReports) {
    
            string[] labels = {"InAssetBundle"};
    
            foreach (var report in buildReports) {
                foreach(var assets in report.AssetGroups.Values) {
                    foreach(var a in assets) {
                        AssetDatabase.SetLabels(a.data, labels);
                        a.ReleaseData();
                    }
                }
            }
        }
    }
    
  6. Log in to comment