Assuming you are loading an Asset Bundle somewhere in that scene intialization, it couldn’t load. Some reasons for this are: Badly formed URI(not pointing to the right place), no wifi, corrupted bundle, or bundle is made from a different Unity version.
Can it load the bundle in the Editor, and is it on disk or on a server?
All asset bundles load fine in the Editor.
The asset bundles are stored in the application asset path so wifi is not an option for a fail point.
The assets are build by this script:
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class BuildAssetBundlesFromDirectory
{
[@MenuItem("Assets/Build AssetBundles From Directory of Files - No dependency tracking")]
static void ExportAssetBundles ()
{
// Get the selected directory
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
Debug.Log(path);
if (path.Length != 0)
{
path = path.Replace("Assets/", "");
Debug.Log(path);
string [] fileEntries = Directory.GetFiles(Application.dataPath+"/"+path);
foreach(string fileName in fileEntries)
{
Debug.Log(fileName);
string filePath = fileName.Replace("\\", "/");
int index = filePath.LastIndexOf("/");
filePath = filePath.Substring(index);
Debug.Log(filePath);
string localPath = "Assets/" + path;
// Debug.Log(localPath);
if (index > 0)
localPath += filePath;
Debug.Log(localPath);
Object t = AssetDatabase.LoadMainAssetAtPath(localPath);
if (t != null)
{
Debug.Log(t.name);
string bundlePath = "Assets/" + path + "/" + t.name + ".unity3d";
Debug.Log(bundlePath);
// Build the resource file from the active selection.
BuildPipeline.BuildAssetBundle(t, null, bundlePath, BuildAssetBundleOptions.CompleteAssets,BuildTarget.iPhone);
}
}
}
}
}
as long the path to the path to the asset is working i don’t see the problem.
i generate the path for the www command like this:
I got it:
Assets/… is not explicitly copied over to the device. Only 3 internal folders can be copied over, and only 1 in a usable form:
Assets/Resources will place all assets in that folder into an LMZA compressed blob for use with Resources.Load
Assets/Plugins is used to automate plugin copying, so if you have extra DLLs or native plugins you can use this
Assets/StreamingAssets gets renamed to Application.dataPath + “/Raw/” and copies the files directly as they are. It was originally used for movie files but it also works great for Asset Bundles.
Place your Asset Bundles into a folder called Streaming Assets and retrieve it on device in a folder called Raw. You can get a better idea by looking at the .app build by XCode and examining the contents (as well as using Debug.Log of your path on device) to make sure these match.
So i have to place my assets inside of Assets/StreamingAssets and get the data on the device from the directory Assets/Raw?
If thats true i have simply make a device based switch and everything is working fine.
Edit:
Ok the loading is now working fine.
But like allways …one problem solved and another is popping up.
It looks like unity is eating up memory when using a assetBundle.
alter loading some pages the application crashes.
i even tried to unload the asset but it does not help.
new_www.assetBundle.Unload(false);
(new_www is the www that was used to download the asset bundle),
In editor is the memory usage just on loading the scene uses 460 MB of Memory(according to the Profiler), but it’s not video or texture memory.
If i switch like 10 or more sides in editor the Memory usage(according to the Profiler) uses up to 1,5 GB of Memory.
Measure memory via Instruments (App that comes with XCode). The Profiler includes Editor memory and special editor hooks. Using Instruments will allow you to measure memory usage on device. Also if depending on devices you have different targets. Anywhere from 40 megs to 150 megs CAN be acceptable ranges depending on which devices you plan on supporting.
Also you will need to either unreference assets and call Resources.UnloadUnusedAssets(), or Unload with true as a parameter, or change Scenes to get Unity based assets to start being unloaded.
I also have the same problem, my application crashes on iphone.
I’m also using “www.assetBundle.Unload(false);” after each assetbundle loading, but hey, each asset bundle is at worse a few hundreds Kb, how could it be a memory allocation problem?