28-02-2021, 08:44 PM
Hi Jose,
Here is the code that is loading Asset Bundles and resulting the error when attempting to Destroy the instance from the Asset Bundle.
If I call the DeleteClothingItem separately everything works fine. It's only when calling DeleteClothingItem while InstatiateObjectFromBundle in same method that the error and subsequent crash occurs.
Here is the code that is loading Asset Bundles and resulting the error when attempting to Destroy the instance from the Asset Bundle.
Code:
public GameObject femModel;
AssetBundle myLoadedAssetbundle;
public string path;
public string prefabName;
public GameObject prefab;
public GameObject newClone;
void LoadAssetBundle(string bundleUrl)
{
if (myLoadedAssetbundle != null)
{
myLoadedAssetbundle.Unload(true);
}
myLoadedAssetbundle = AssetBundle.LoadFromFile(bundleUrl);
Debug.Log(myLoadedAssetbundle == null ? " failed to load AssetBundle" : " AssetBundle successfully loaded");
}
void InstatiateObjectFromBundle(string assetName)
{
prefab = myLoadedAssetbundle.LoadAsset<GameObject>(assetName);
newClone = Instantiate(prefab, transform.position, transform.rotation, femModel.transform);
}
public void LoadOutfitAssetBundle(string path)
{
LoadAssetBundle(path);
}
public void LoadOutfitBundlePrefab(string prefabName)
{
DeleteClothingItem();
InstatiateObjectFromBundle(prefabName);
}
public void DeleteClothingItem ()
{
if (newClone != null)
{
DestroyImmediate(newClone, true);
}
}
If I call the DeleteClothingItem separately everything works fine. It's only when calling DeleteClothingItem while InstatiateObjectFromBundle in same method that the error and subsequent crash occurs.