Custom editor, how to select an empty project folder in code

Hi all,

as the title says, I’m struggling to work out a way to select a project folder from code if it’s empty, and extensive Googling hasn’t provided a solution as yet.

I’m okay if the folder has something in it, because I can use Selection.activeGameObject to select the object in the folder and in so doing select the folder, but for the life of me I can’t find out a way to select an empty folder.

I’m starting to think it’s actually not possible as things stand, but I’m hoping someone can tell me otherwise :slight_smile:

I’m not sure this is what you want to do but if you’re just looking to select an empty folder in the editor’s Project window you can do this:

EditorUtility.FocusProjectWindow();
UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>("Assets/MyNewEmptyFolder");
Selection.activeObject = obj;
1 Like

Yep, that does the job, thanks very much!

I’d already tried something very similar AssetDatabase.LoadAssetAtPath(“Folder Path”), which returned null. So near and yet so far! :slight_smile:

Great, maybe because it’s a folder the ‘DefaultAsset’ type was too specific? Glad it’s working anyway!

1 Like