Search Unity

With DeleteFileOrDirectory comes much responsibility

Discussion in 'Scripting' started by ghoulfool, Apr 23, 2014.

  1. ghoulfool

    ghoulfool

    Joined:
    Jan 14, 2014
    Posts:
    16
    I was hoping to clear up some of the extraneous assets created when importing an FBX file.

    Code (csharp):
    1.  
    2.         if (assetPath.Contains(".fbm"))
    3.         {
    4.             string assetName = assetPath.ToString();
    5.             Debug.Log("Nuking: " + assetName);
    6.              // FileUtil.DeleteFileOrDirectory(assetName); // Bad code; no biscuit!
    7.  
    8.         }
    9.  
    The DeleteFileOrDirectory here causes Unity to have a small heart attack. Without having to do the trial error loop with such a big crash I was wonder where I was going wrong?
     
  2. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    I believe each one of those calls causes a refresh of the Assets in the project, use System.IO.File.Delete instead then call AssetDatabase.Refresh() and see if that helps