- Home /
Trouble building AssetBundle database for iOS
I'm trying to create a AssetBundle database for iOS but I'm having problems setting the BuildTarget. The rest of my asset bundles programatically have there BuildTarget set to BuildTarget.iPhone but I'm unable to set the target without making my AssetDatabase unreadable.
The error im getting:
The file can not be loaded because it was created for another build target that is not compatible with this platform. Please make sure to build asset bundles using the build target platform that it is used by. File's Build target is: 6
This is the script in which Im creating the database.
List<CharacterElement> characterElements = new List<CharacterElement>();
// As a CharacterElement needs the name of the assetbundle
// that contains its assets, we go through all assetbundles
// to match them to the materials we find.
string[] assetbundles = Directory.GetFiles(CreateAssetbundles.AssetbundlePath);
string[] materials = Directory.GetFiles("Assets/characters", "*.mat", SearchOption.AllDirectories);
foreach (string material in materials)
{
foreach (string bundle in assetbundles)
{
FileInfo bundleFI = new FileInfo(bundle);
FileInfo materialFI = new FileInfo(material);
string bundleName = bundleFI.Name.Replace(".assetbundle", "");
if (!materialFI.Name.StartsWith(bundleName)) continue;
if (!material.Contains("Per Texture Materials")) continue;
characterElements.Add(new CharacterElement(materialFI.Name.Replace(".mat", ""), bundleFI.Name));
break;
}
}
// After collecting all CharacterElements we store them in an
// assetbundle using a ScriptableObject.
// Create a ScriptableObject that contains the lis t of CharacterElements.
CharacterElementHolder t = ScriptableObject.CreateInstance<CharacterElementHolder> ();
t.content = characterElements;
// Save the ScriptableObject and load the resulting asset so it can
// be added to an assetbundle.
string p = "Assets/CharacterElementDatabase.asset";
AssetDatabase.CreateAsset(t, p);
Object o = AssetDatabase.LoadAssetAtPath(p, typeof(CharacterElementHolder));
// Build the CharacterElementDatabase assetbundle.
//BuildPipeline.BuildPlayer( levels, "WebPlayerBuild", BuildTarget.WebPlayer, BuildOptions.None);
BuildPipeline.BuildAssetBundle(o, null, CreateAssetbundles.AssetbundlePath + "CharacterElementDatabase.assetbundle");
// Delete the ScriptableObject.
AssetDatabase.DeleteAsset(p);
Anyone have any idea what I can do. barring in mind that when I set the BuildTarget in the script above I get a unreadable exception.
Once last thing the way in which im fetching the Bundles is through a WWW download, if that might be some sort of cause.
Cheers - Caius
Answer by Caiuse · Nov 16, 2011 at 11:19 AM
Solved, if you run into problem, check and double check the BuildTarget of all the assetBundles.
Exactly as you said: check, double check and triple check hehe thanks ;)
Your answer