Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

My folder is unusable after using AssetDataBase.CreateAsset !

Discussion in 'Editor & General Support' started by Asalfin, Jul 4, 2022.

  1. Asalfin

    Asalfin

    Joined:
    Mar 21, 2019
    Posts:
    11
    Hi !
    I was experimenting with AssetDataBase.CreateAsset, and I put a Path that did not have a new name in the end, only had the path to a folder, like this for example : "Asset/FolderName". However after I ran the script, it changed the folder itself (I thought it would create the asset at the specified path), and now, Unity can't open the folder anymore and shows this error :
    Unable to open Assets/_Common/Environmental/GrassShader/_GrassUpgrade: Check external application preferences.
    I also can't open the folder in Windows because it became a File with no extension.
    I can't show you the script I used since my script was inside the folder ! I remember using only this :
    AssetDatabase.CreateAsset(MeshToSave, FilePath);
    AssetDatabase.SaveAsset();

    Is there any way to recover my files ? If not then am I understanding that basically you could delete your entire Asset folder if you were to mess up one string ? Seems kinda dangerous to me ! Is there any alternative for creating a file ?

    Thanks in advance for any help you can give !
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,015
    Yeah looks like you wrote the mesh to the folder. It's not actually an invalid thing to do, and this behaviour is clearly shown in the documentation for AssetDatabase.CreateAsset(). The path includes the directory, file name, and the file extension in the one string, so be sure make that distinction when writing this functionality.

    I did some googling but doesn't look like there's much of a way to return a file into a folder. So unless you are using version control software... lesson learnt.
     
  3. Asalfin

    Asalfin

    Joined:
    Mar 21, 2019
    Posts:
    11
    Thanks for your answer ! I had only one small script in the folder so it's not a big deal but I guess now I'll remember not to make the same mistake again.