Use List with EditorGUILayout.Popup

Hi, I’m looking for ways to use dynamic arrays with EditorGUILayout.Popup in a Custom Editor.
I do not have a certain number of elements to define as
string [ ] options = new string [ ] {“0”, “1”, “[…]”}
but they are variables.
The solution would seem to be to use
List myList = new List ()
but Unity gives me error (cannot convert List to string[ ]).
I’ve been using Unity for a short time so it may be that I’m wrong.
Is there a way to use List or possibly to overwrite string [ ] or adding or removing one element from code?

Try using “myList.ToArray()” form System.Linq;

Thanks! Unfortunately I have already tried:
List options = new List();
and
EditorGUILayout.Popup("Current editing Group: ", ListGroup, options.ToArray, EditorStyles.popup);
(cannot convert method group to string[ ])
Is this what you were suggesting to me or did I misunderstand?

ToArray is a method, not a property or field.
So add the parameter parens like this:

EditorGUILayout.Popup("Current editing Group: ", ListGroup, options.ToArray**()**, EditorStyles.popup);

Also, you can use ArrayUtility.Add

Also, from the sound of it you are a beginner in C#.
Starting with unity is a really bad idea as it teaches a lot of bad ways to do things (which are ok to do, but only in the context of unity because as game developers we absolutely have to tickle out every last drop of performance :P)
For your own good I’d advise to maybe take some time to get more used to C# and then start with Unity.
It will pay of in the long run.

1 Like

Thanks for your quick support.
Unfortunately this is not a total lack of preparation but also distraction, since some lines below I use ToString () regularly with round brackets :sweat_smile:.
C# is not so difficult when until yesterday it was used Visual Basic, Delphi, PHP but what I really have to do is pay more attention.
Without your intervention I would still be there to lose myself on how to do what I had already found.
Thank you very much.