here’s my situation: To allow for modding I have now split my Unity project into two projects. One contains the scripts and non-moddable content, the other the moddable content (i.e. my default content). Using Unity 5.x, I can export the moddable content into an AssetBundle. I can also load the AssetBundle into the build. So far so good.
But how do I work with the AssetBundle in the Editor, i.e. when I preview my game?
Here it says I can “fake import” an AssetBundle in the Editor. But what does:
mean exactly? Does that mean that I have to place the AssetBundle in the Resources folder? That’s not what this folder is for, right? Why can’t I load an AssetBundle from anywhere on my disc? If I can’t, I need to split my code via processing directions, right? Isn’t that highly impractical?
When I google the problem I do find stuff that’s obviously wrong or outdated, given how much the AssetBundle system changed in 5.x.
What Resources.LoadAssetAtPath (now AssetDatabase.LoadAssetAtPath) does is simply load the asset with the given path (as long as it’s in the project), it’s not like loading from an AssetBundle at all. There are several things that are different.
AssetDatabase.LoadAssetAtPath requires (afaik) an extension for the file you’re wanting to load (eg. .prefab,.png), this is not required when loading from an asset bundle. Another thing that is different is that LoadAssetAtPath has no async counter part, while loading from an AssetBundle does, so if that is part of your pipeline, you’ll only be able to load synchronously in the Editor. Finally LoadAssetAtPath only has one stage to load a file, you pass in the path, you get an asset back. If you load from an asset bundle, you must first load the asset bundle, then request the asset (this can be done synchronously or asynchronously).
Loading times will obviously be different in both situations as well, as you have to load the bundle before requesting the asset and if your asset bundle is compressed, it’ll take even longer to load, as it has to decompress the bundle first.
All that being said, we often do follow this approach of using AssetDatabase.LoadAssetAtPath in the editor, as the manual says, it avoids having to constantly rebuild your bundles. You just need to be aware that they are not the same thing!