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.

Bug Unity does not recognize the "Application.dataPath" as a project location and the directory is fine

Discussion in 'Editor & General Support' started by enriboliveira, Feb 9, 2023.

  1. enriboliveira

    enriboliveira

    Joined:
    Dec 22, 2018
    Posts:
    2
    I just wanted to script-create assets, so I figured I should use "AssetDatabase.CreateAsset(example, path);" but I got the error "Couldn't create asset file! (lots of error code)".
    But now for some reason the error has changed, until then I had only changed the code that I show below:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.IO;
    3. using UnityEditor;
    4.  
    5. public class MusicasFinderAndAjuster : MonoBehaviour
    6. {
    7.     string BasePath;
    8.     private void Start()
    9.     {
    10.     }
    11.     private void Update()
    12.     {
    13.         if (Input.GetKeyDown(KeyCode.Alpha3))
    14.         {
    15.             print(AssetDatabase.IsValidFolder(Application.dataPath));
    16.             print(AssetDatabase.IsValidFolder(Application.dataPath+"/Assets"));
    17.             scriptableExemple example = ScriptableObject.CreateInstance<scriptableExemple>();
    18.             // path has to start at "Assets"
    19.             string path = System.IO.Directory.GetCurrentDirectory() + "/a.asset";
    20.             //path.Remove()
    21.             Debug.LogWarning(path);
    22.             GUIUtility.systemCopyBuffer = System.IO.Directory.GetCurrentDirectory();
    23.             AssetDatabase.CreateAsset(example, path);
    24.         }
    25.     }
    26. }
    27.  

    But now unity simply tells me that the "Application.dataPath" path is not a valid path for this function, or something like that.
    I searched a lot and I was led to understand that maybe the project is not recognizing the place where it is and I should tinker with the "Version Controler" or "External Tools", but it doesn't solve anything and I can't actually do anything.
    Here are some photos of errors and other things: upload_2023-2-8_23-41-38.png upload_2023-2-8_23-42-7.png