Like the title says; is there any way to check if a specific asset bundle has already been loaded?
I keep coming across this exception:
The asset bundle ‘file_name_here.unity3d’ can’t be loaded because another asset bundle with the same files are already loaded
UnityEngine.WWW:get_assetBundle()
We have every level of our game in separate bundles so that we only have short load times between them. The problem is, if a user goes to play the same level twice in a single session the asset bundle is loaded twice and we get the above mentioned exception.
With the way our content is loaded (every level loads the next level’s asset bundle), when I move onto the newly loaded level I no longer have reference to the bundle to keep track of what I have loaded.
All of this could be easily avoided if I could just check to see if that AssetBundle has been loaded before.
I figure if the engine can throw an exception about it, obviously it is keeping track of it somewhere. I’ve scoured the docs but I can’t seem to turn anything up.
Any ideas?
Okay I solved this by creating a playerpref for each level, and when the level wakes I call:
PlayerPrefs.SetInt("level"+(int)LEVELID+"loaded",1);
As I mentioned above, every following level is loaded upon completion of the current level. So during this load time I simply check:
if(PlayerPrefs.GetInt("level"+(int)LEVELID+"loaded") == 0)
{
DoLoad();
}
else //already downloaded
{
Application.LoadLevel("LevelName");
}
Of course, since PlayerPrefs are persistent, at the start of your game you will need to reset your data. I found that it worked for me by putting this in my first executing script in my main (first loaded) level.
if(Time.time < 1)
{
//recursively set all the appropriate PlayerPrefs to 0
}
I use this method because before Time.time reaches 1 the application would have executed the Awake() method I needed to do this but the user could not have loaded anything which might cause breakage later on.
Anyway, that is my solution, however I think giving us some run-time access to whether or not a bundle has been loaded would be greatly beneficial.