- Home /
How can I put a list of filenames into an editor menu?
The EditorGUILayout.Popup method displays a drop-down menu so the user can select from a list of strings. However, any slashes in the option strings are converted into another level of child menu. This is cool when you want nested menus, not so cool when you're trying to give the user a list of filenames to choose from.
Is there a way to prevent this behaviour? Or other suggestions on how to easily throw a drop-down menu into my EditorWindow?
Ah, I can pass an array of GUIContents, doesn't have to be strings. I'll try that in the morning, pretty sure it will work.
Answer by yoyo · Feb 08, 2011 at 05:41 PM
Turns out backslashes work fine, so I'm converting front-slashes to backslashes for use as menu options, then converting the result back to front-slashes when I use the filename (redundant under Windows, where either slash works for the file system API's, but needed on Mac).
I did notice a few times when backslashes seemed NOT to work, but I believe this was because my editor window class was not being fully reinitialized as I was modifying its code and recompiling. (Seems odd, but I'm not going to bother investigating.)
A backslash will not work on OS X (as far as accessing files goes).
Answer by Eric5h5 · Feb 08, 2011 at 02:32 AM
An array of GUIContents won't work either, alas. You can replace "/
" with "" instead (i.e, the fraction slash character with a space before and after, instead of the standard slash).
for knowing it wouldn't work :-( ... but I can't give you credit for the right answer because I don't have that slash on my keyboard, and while I was able to convert my editor to UTF-8 and copy-paste into my code, the slash turns into an "a" with an accent over it when I drop the menu.
This is what appears -- "". (Note that I'm on a Windows PC.)
That's too bad; works fine on OS X, and it's standard Unicode, so I don't know what the problem would be.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103317im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
EditorGUILayout.ObjectField cannot be changed. 1 Answer
Recreate default editor look manually without base.OnInspectorGUI [UnityEditor] 2 Answers
Fix editor TextField cursor alignment 1 Answer
Custom inspector difficulties creating a Box / Group like widget 1 Answer
How can I determine when user presses enter in an editor text field? 3 Answers