- Home /
AssetDatabase.CreateFolder not defined?
For some reason when I try to use the function AssetDatabase.CreateFolder(string, string) my code will not compile. This is really weird considering this is in the same editor script where I was able to use AssetDatabase.CreateAsset without any problems.
The exact error I get is:
Error CS0117: 'UnityEditor.AssetDatabase' does not contain a definition for 'CreateFolder' (CS0117)
Answer by Graham-Dunnett · Jul 29, 2011 at 08:17 PM
This works perfectly for me:
//javascript
@MenuItem ("MyMenu/Do Something")
static function DoSomething () {
var myGuid : String = AssetDatabase.CreateFolder("Assets", "My Folder");
var newFolderPath = AssetDatabase.GUIDToAssetPath(myGuid);
Debug.Log ("got :" + newFolderPath);
}
I just whacked it into a javascript file in Assets/Editor.
However, if you look at:
http://unity3d.com/support/documentation/ScriptReference/40_history.html
You'll see that AssetDatabase.CreateFolder was added at Unity 3.4, so there is no chance at all that this will work in your 3.3 project. When working with older versions of Unity is is always best to consult the documentation that shipped with the version you use. The content we host online is always for the latest version. I'll close your bug report as "By Design".
Okay, I was wondering if the version might be the case. I just found it weird since $$anonymous$$onoDevelop auto-completed it for me. Then again, that might be some artifact of me installing/uninstalling Unity 3.4.
Thanks for your help!
Answer by sharat · Jul 29, 2011 at 06:01 PM
I'll probably just submit a bug about this. As far as I can tell, using the System version seems to work for me, so I recommend using
System.IO.Directory.CreateDirectory(string)
as a substitute.
Bug report has been filed.
http://fogbugz.unity3d.com/default.asp?413396_3a4ur89cclh41nqg