Delegates & EditorGUI function overloads in C#

I’m doing some editor window stuff making it easier to construct windows for me. But I wrote this bare bones case to demonstrate the issue I’m having…

I have a class that handles some things for me, but I also want to use Unity’s fields and not create a subclass for every possible field. So I wanted to make a class accept a function delegate to handle things for me AND call unity’s field.

So to me, this seems like it should work (code at the bottom), but on passing the function to the constructor I get this error:

error CS0123: A method or delegate UnityEditor.EditorGUI.Toggle(UnityEngine.Rect, bool)' parameters do not match delegate System.Func(UnityEngine.Rect, string)’ parameters

To me it seems that the wrong overload of EditorGUI.Toggle is passed, as Toggle has a function that takes a ; but instead it takes the first overload of Toggle which just takes . Am I misunderstanding the capabilities of Delegates, doing something wrong, or is this error just very ambiguous and is something else the matter?

using UnityEngine;
using UnityEditor;
using System;


public class ShaderGeneratorWindow : EditorWindow
{
    [MenuItem("Poo-Brain/Shader generator")]
    static void Init()
    {
        EditorWindow.GetWindow(typeof(ShaderGeneratorWindow));
        new USystemField<bool>("Vertex colors", false, EditorGUI.Toggle);
    }
}


public class USystemField<T>
{
    public string label;
    public T fieldvalue;
    public Func<Rect, string, T> drawfunc;


    public USystemField(string inLabel, T inValue, Func<Rect, string, T> inDrawfunc)
    {
        label = inLabel;
        fieldvalue = inValue;
        drawfunc = inDrawfunc;
    }
}

Thanks for reading, I hope someone with more understanding than me can help me out…

If you want to call this EditorGUI method:

static bool Toggle(Rect position, string label, bool value);

then you have to use this:

Func<Rect, string, bool, bool>

Last generic type denotes return value, so in your implementation, you tried to call non-existing method:

bool Toggle(Rect position, string label)

Additionally, it is not required to use generic type T in your Func definition, because Toggle methods aren’t generic.