This has been driving me crazy for some time but only recently got to be a big enough problem to try and find a solution.
I wrote a script to build Windows/Windows64/OSX asset bundles all at the same time with one menu item. This didn’t used to be a problem because I was just building Windows, however every time I run it Unity switches the Build Settings → Platform to Web, which resets/reimports scripts. Plus my game doesn’t build using Web anyway (file access, etc).
Here’s the gist of what I’m doing:
[@MenuItem("Asset Bundle/Build/Build Selected ToC")]
static void BuildSelectedAssetBundle()
{
BuildAssetBundle(BuildTarget.StandaloneWindows);
BuildAssetBundle(BuildTarget.StandaloneWindows64);
BuildAssetBundle(BuildTarget.StandaloneOSXIntel);
}
static void BuildAssetBundle(BuildTarget buildTarget)
{
<compute a bunch of paths, gather resources, create directories, etc>
BuildPipeline.BuildStreamedSceneAssetBundle(<scene files>, <save filename>,
buildTarget);
BuildPipeline.BuildAssetBundle(<main asset>, null, <save filename>,
BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.CollectDependencies);
}
The first call to BuildAssetBundle(BuildTarget.StandaloneWindows) works fine, then Unity automatically switches to Web, resets everything, and the second call using BuildTarget.StandaloneWindows64 fails. At this point, opening the Build Settings window shows a Platform of Web, every single time.
So, question is, why is Unity doing this and what do I have to do to make it stop?
Thanks in advance!
Russ Glaeser