Folders inside an AssetBundle

How can I pack an AssetBundle to include a folder structure?

Or, can I at least somehow rename an asset when I pack it, to differentiate files that came from different folders, but have the same name?

You don't, the names are flattened by default. But you may change the names inside the bundle with:

  • BuildPipeline.BuildAssetBundleExplicitAssetNames

This allows you to use names that match your folder structure. Those names may be used with AssetBundle.Load().

I have used BuildAssetBundleExplicitAssetNames to sulfix my assets (inside the bundle) with the guid that can be obtained with AssetDatabase.AssetPathToGUID.

Build multiple bundles for each folder and then pack it inside one final bundle

When packaging an asset bundle, the entire folder structure is preserved 100%. Just make the directory structure is exactly the way you want it in Unity, select all the relevant files (hold Ctrl or Cmd on Mac), and then Export the asset bundle. You don't need to do anything special in terms of the folder hierarchy.