How do you set asset bundle name on prefabs through code?

Hi,

I’ve been away from Unity for a year so I’m a bit confused by what has changed :slight_smile:

I have an old project where I had placed all assets that where to be built into asset bundles in a folder named “AssetBundles”. Now I want to migrate this system to the new awesome 5.* asset bundle system. I could go through all the assets manually and set them to: “go_cool.unity3d” etc but I have about 500 of them so I thought I would write a script that would just set the asset bundle name to the same name as the asset for all assets in that folder.

I couldn’t figure out how to do this so I though an AssetPostProcessor should do the trick. This seems to work in setting assetImport.assetName on textures. But I can’t figure out how to do this on prefabs/gameobjects. The “on post process all assets” is a static method for some reason.
The “on pre process model” is not called on game objects.
The “OnPostprocessGameObjectWithUserProperties” I can’t find any information about how to trigger this one.

Sincerely thankful for any help :slight_smile:

/J

This should work for any assets(Not scripts maybe).

    [MenuItem("Test/ChangeBundleName")]
    static void ChangeBundleName()
    {
        string assetPath = AssetDatabase.GetAssetPath(Selection.activeInstanceID);
        AssetImporter.GetAtPath(assetPath).SetAssetBundleNameAndVariant("testBundle", "");
    }