提问人:Muhammet Demir 提问时间:12/28/2020 更新时间:11/21/2023 访问量:2125
无法加载,因为已加载另一个具有相同文件的 AssetBundle。加载不同捆绑包时出错
can't be loaded because another AssetBundle with the same files is already loaded. error while loading different bundles
问:
我试过从 URL 加载资产包。当我只加载单个资产包时,它运行良好。但是,如果我尝试加载多个资源包,Unity 会给出以下错误:The AssetBundle 'https://example.com/uc?export=download&id=1234567' can't be loaded because another AssetBundle with the same files is already loaded.
示例代码如下
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using TMPro;
public class sahnecagir : MonoBehaviour
{
public TextMeshProUGUI Log;
// Start is called before the first frame update
void Start()
{
StartCoroutine(LoadBundleFromUrl("https://example.com/uc?export=download&id=123456", 2, 0, (uint)Crc.Gifts));
}
IEnumerator LoadBundleFromUrl(string url, int tip, uint version, uint crc)
{
using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(url, version, crc))
{
uwr.SendWebRequest();
while (!uwr.isDone)
{
if(tip == 1) Log.text = "Rooms loading " + (uwr.downloadProgress * 100).ToString("0") + "%";
else if(tip == 2) Log.text = "Gifts loading " + (uwr.downloadProgress * 100).ToString("0") + "%";
yield return null;
}
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.Log(uwr.error);
}
else
{
if (tip == 1)
{
MainConfig.Instance.RoomBgBundle = DownloadHandlerAssetBundle.GetContent(uwr);
}
else if (tip == 2)
{
MainConfig.Instance.GiftBundle = DownloadHandlerAssetBundle.GetContent(uwr);
}
}
if (uwr.isDone && tip == 1)
{
Log.text = "Rooms loading 100%";
StartCoroutine(LoadBundleFromUrl("https://example.com/uc?export=download&id=1234567", 2, 0, 0));
}
else
{
Log.text = "Gifts loading 100%";
}
yield return null;
}
}
}
答:
1赞
bluewave41
3/10/2022
#1
就我而言,我一直在尝试修改包含不同文件的捆绑包,但 Unity 拒绝加载两个不同的文件,即使它们具有不同的名称、不同的结构、内部不同的文件,什么都没有。
在 Notepad++ 中打开捆绑包会显示我假设的 CAB-a317cdbf067bab183d6dd12d870c1407 的“容器名称”作为示例。这似乎是 Unity 正在检查以确定捆绑包是否“相同”的内容。
一个简单的查找并替换为不同的名称和繁荣。捆绑包现在加载。
0赞
yasirkula
11/21/2023
#2
如果使用相同的 AssetBundleBuild.assetBundleName 参数创建了多个 AssetBundle,则可能会出现此问题。为每个 AssetBundle 提供唯一的 s 可以解决此问题(即使您之后重命名生成的 AssetBundle 文件)。assetBundleName
评论