Basic Editor Window Script fails to create asset in OnGUI with "Couldn't create asset file!" and "UnityException: Creating asset at path [path] failed."

Super confused :frowning: I thought this was how you were supposed to create new assets?!

I created a repo here:
https://github.com/scrapcupcake/UnityEditorBug

And submitted a bug to Unity:
http://fogbugz.unity3d.com/default.asp?672290_6brq5t26hruhs7n2

  1. What happened
    Super basic call to AssetDatabase.CreateAsset returns the following errors, which are… super generic and provide me no direction to solve the issue.

Couldn’t create asset file!
UnityEditor.AssetDatabase:CreateAsset(Object, String)
TileBoardEditor:OnGUI() (at Assets/Editor/TileBoardEditor.cs:26)
UnityEditor.DockArea:OnGUI()

UnityException: Creating asset at path /Users/scrapcupcake/Documents/Personal Projects/Unity/BugTest/Assets/Board.asset failed.
TileBoardEditor.OnGUI () (at Assets/Editor/TileBoardEditor.cs:26)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

  1. How can we reproduce it using the example you attached.

Window > Match 3 Board Editor
In created window:
Click “New Board”
Accept default path (or any other path I’ve tested, same result)

Aaaand I solved it.

Did you know that CreateAsset must take a path relative to the project? And that it’ll barf with the above abominable generic errors if you give it an absolute path?

I SURE DIDN’T.

There is a few hours of my life that I’d really really really like to have back.