Custom object field of List ?

Hey guys !

Trying to do my own custom editor… I need to expose / access in the UI a list of float (but note that it could be a list of anything)
Unity already supports that natively so you can add/remove/edit template list directly in the editor…
But the question is: Can you do that in your custom editor ??

So basicaly I’ve tried something like that :

List<float> 	Params;
Params = (List<float>) EditorGUILayout.ObjectField( "Parameters", (UnityEngine.Object)Params, typeof(List<float>) );

Unfortunately I have a “cannot convert type from List to UnityEngine.Object” compiler error so it looks this is not the correct way of doing that…

I’m pretty sure it’s possible… any help / hint / code / thing would be greatly appreciated :wink:


Basically, use another data type for your object than a List. What is is saying is that there is no way of converting from a System.Collections.Generic.List to a UntiyEngine.Object, which is true.

What I would do is write a wrapper class for List that extends UnityEngine.Object, like this:

public class ListWrapper<T> : UnityEngine.Object {
    public List<T> objects = new List<T>();

Then you should be able to use it like this:

ListWrapper<float>     Params;
Params = (ListWrapper<float>) EditorGUILayout.ObjectField( "Parameters", (UnityEngine.Object)Params, typeof(ListWrapper<float>) );

Unity might not like the generics, so you might want to replace them if this does not work.