0
\$\begingroup\$

I need to create a ScriptableObject through script, So I used AssetDatabase.CreateAsset but it creates inside project folders only.

So is there a way to create the ScriptableObject through script outside project folders?

And if there are no other ways, how can I convert the choosen folder path to a suitable path for AssetDatabase.CreateAsset?

like E:/Projects/Time System/Assets/ChoosenFolder to Assets/ChoosenFolder.

I'm choosing the folder by string path = EditorUtility.OpenFolderPanel("Choose Folder", "", "");

\$\endgroup\$
8
  • \$\begingroup\$ Why not create it in the project folder first and use something like docs.unity3d.com/ScriptReference/… next? \$\endgroup\$
    – Zibelas
    Commented Jul 8 at 13:14
  • \$\begingroup\$ what's more important to me right now is converting the choosen folder path to a suitable path for AssetDatabase.CreateAsset, but it's good idea @Zibelas \$\endgroup\$
    – Ahmed Dyaa
    Commented Jul 8 at 13:21
  • \$\begingroup\$ There is no reason. Use a fixed, temporary path for AssetDatabase.CreateAsset and pass the path of EditorUtility.OpenFolderPanel to the FileUtil.MoveFileOrDirectory with the fixed temp path and the users chosen one. \$\endgroup\$
    – Zibelas
    Commented Jul 8 at 13:48
  • \$\begingroup\$ Yes that's for creating the scriptable object outside the project but I need to cover all possibilities, for creating outside I will create the scriptable object at "Assets/" then moving it to where ever I chose by EditorUtility.OpenFolderPanel, but if the user chose a folder inside the project by EditorUtility.OpenFolderPanel I can't use the path of it with AssetDatabase.CreateAsset, for example, if the user chose Created Items folder inside folder assets it will appear like this E:/Projects/Time System/Assets/Created Items and AssetDatabase.CreateAsset will refuse to create to it \$\endgroup\$
    – Ahmed Dyaa
    Commented Jul 8 at 16:15
  • \$\begingroup\$ so the path E:/Projects/Time System/Assets/Created Items should be converted to this Assets/Created Items that's what I mentioned as being more important to me \$\endgroup\$
    – Ahmed Dyaa
    Commented Jul 8 at 16:17

0

You must log in to answer this question.

Browse other questions tagged .