Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Missing Ref Exception when deleting Obi Cloth
#3
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. 


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.
Reply


Messages In This Thread
RE: Missing Ref Exception when deleting Obi Cloth - by fluidman84 - 28-02-2021, 08:44 PM