Jump to content

The AssetBundle 'name' can't be loaded...


Recommended Posts

If you try to load more than one asset from a bundle using AssetLoader, you get this message for each asset after the first:

Quote

The AssetBundle 'name' can't be loaded because another AssetBundle with the same files are already loaded

AssetLoader: Bundle is null

This was mentioned in the "How to convert your Plugin" 1.1 thread, but that sub-forum is now hidden, so I don't know if there was discussion elsewhere.

I've been trying to work around this issue, and one thing I find is that AssetLoader.LoadedBundles has an AssetBundle in it when the loader callback fires, and the bundle has all three shaders I was looking for.  So, I suppose that is one way to work around this behavior.  The AssetBundle doesn't have a name, so I still have to do some extra checks in case other asset bundles show up in the list.

Here's the code snippet I'm using to trigger this error:

KSPAssets.AssetDefinition[] rpmShaders = KSPAssets.Loaders.AssetLoader.GetAssetDefinitionsWithType("JSI/RasterPropMonitor/rasterpropmonitor", typeof(Shader));
if(rpmShaders == null || rpmShaders.Length == 0)
{
    // Log an error
    return;
}

KSPAssets.Loaders.AssetLoader.LoadAssets(AssetsLoaded, rpmShaders);

rpmShaders has 3 objects in it.  When the callback gets called, only AssetLoader.Loader.objects[0] is valid - the [1] and [2] entries are null.

 

Link to comment
Share on other sites

58 minutes ago, JPLRepo said:

You mean this one?

 

That's where I saw the problem mentioned, near the end of the thread, but there's no solution in it, and the rest of that forum was shut down, so I don't know if anyone else worked around it.  I've got a workaround now.  It ain't pretty, but it does the trick. But it'd be much better code if the asset loader didn't barf when asked to load more than one thing, particularly since its interface implies that it can load multiple assets.

Link to comment
Share on other sites

Unity 5.2.4? assetbundles from anything newer than 5.2.4 gives you empty compiled assetbundle and you get the errors from OP when attempting to load the empty assetbundle. Check the assetbundle with UnityStudio for content? 

Edited by nli2work
Link to comment
Share on other sites

Or it could be as @DMagic @Nils277 and myself just discovered with KSPedia asset bundles, which could be related to this, as it seems to be a dependency bug inside the stock AssetLoader code.
We have discovered that if you create KSPedia asset bundles with references to the squadcore.ksp asset bundle that the loader bugs out and fails.
Check you aren't referencing, (using) anything from the squadcore bundle in your bundle (like a shader, or anything). In the XML that is generated in Unity for your asset check it doesn't have this:

<Dependencies>
    <Dependency>squadcore</Dependency>
  </Dependencies>

 

If it does, copy anything you are referencing from the squadcore bundle into your assets folder or suchlike and reference the copy in your asset bundle so when you compile your asset the Dependencies section in the XML should be blank.
Not sure if this is your issue or not.

Link to comment
Share on other sites

I had the same problem, ended up writing my own Loader following the examples in the Unity docs. Feel free to check out the source code of IR, file is UIAssetsLoader.cs in GUI folder

Link to comment
Share on other sites

@nli2work - Unity 5.2.4f1.  I just triple checked.

@JPLRepo - the sum-total of my XML is

<?xml version="1.0" encoding="utf-8"?>
<KSPBundleDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" UrlName="rasterpropmonitor" Name="rasterpropmonitor" CreatedTime="-8587392394433498673">
  <Author>MOARdV</Author>
  <Info>Shaders for RasterPropMonitor</Info>
  <Assets>
    <Asset Name="RPM/FontShader" Path="Assets/RasterPropMonitor/Shaders/RPM-FontShader.shader" Type="Shader" Url="RasterPropMonitor/Shaders/RPM-FontShader" AutoLoad="false" />
    <Asset Name="RPM/CroppedDisplayShader" Path="Assets/RasterPropMonitor/Shaders/RPM-CroppedDisplayShader.shader" Type="Shader" Url="RasterPropMonitor/Shaders/RPM-CroppedDisplayShader" AutoLoad="false" />
    <Asset Name="RPM/DisplayShader" Path="Assets/RasterPropMonitor/Shaders/RPM-DisplayShader.shader" Type="Shader" Url="RasterPropMonitor/Shaders/RPM-DisplayShader" AutoLoad="false" />
  </Assets>
  <Dependencies />
</KSPBundleDefinition>

Only RPM/FontShader loads successfully if I ask AssetLoader to load all 3.  The other two generate errors and result in null objects in the array.  Even if I split the request into three separate load requests on a single shader apiece, the 2nd and 3rd show errors.

In the "done loading" callback, if I traverse AssetLoader.LoadedBundles, I find the RPM AssetBundle (it's actually the only AssetBundle in that list).  I know it's RPM's, because it contains exactly 3 shaders with the names listed above, even if I only asked AssetLoader to load one of the shaders.

I can indirectly get to the loaded shaders and use them, but what appears to be the intended way to load multiple assets isn't working for me.  It very well may be that I'm doing something wrong creating the asset bundle - I've been fighting with it for a while, but we've finally almost reached a detente.

7 minutes ago, Ziw said:

I had the same problem, ended up writing my own Loader following the examples in the Unity docs. Feel free to check out the source code of IR, file is UIAssetsLoader.cs in GUI folder

I tried using AssetBundle.CreateFromFile, but I got errors to the effect that only uncompressed assets with the format UNITY_RAW could be loaded.  I unchecked the "compress output" checkbox in the asset bundle exporter, but the error didn't go away.

Link to comment
Share on other sites

36 minutes ago, MOARdV said:

 

I tried using AssetBundle.CreateFromFile, but I got errors to the effect that only uncompressed assets with the format UNITY_RAW could be loaded.  I unchecked the "compress output" checkbox in the asset bundle exporter, but the error didn't go away.

Using WWW class is really easy for asset bundles, basic loader is like 30 lines of code taken directly from U ity docs with minimal adjustments

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...