TableMatrix DrawElementMethod accepts no non-static function, gives contradictory error messages.

Issue #700 resolved
Warwick Allison created an issue

The DrawElementMethod to TableMatrix gives contradictory error messages for either of the method signatures it claims to accept. It’s not clear if the problem is just the error messages, or whether the functionality itself is broken, hence bug set to Major, but if the former, it’s probably Minor.

Given this:

    [TableMatrix(DrawElementMethod = "Draw1")]

    public string[,] stringMatrix;
    string Draw1(Rect rect, string name)
    {
        GUI.Label(rect, name);
        return name;
    }

Odin gives the inspector error:

No static methods named Draw1 with a return type of string and with the parameter signature (Rect, string) was found in ….

Non-static method Draw1 must have the following parameters: Rect, string[,], int, int.

Okay, so I read that as saying that for non-static methods, it must take different parameters. So let’s change the DrawElementMethod to match the required signature:

    [TableMatrix(DrawElementMethod = "Draw2")]

    public string[,] stringMatrix;
    string Draw2(Rect rect, string[,] matrix, int x, int y)
    {
        var name = matrix[x, y];
        GUI.Label(rect, name);
        return name;
    }

Then we get this error:

Non-static method Draw2 must have the following parameters: Rect, string.

No static methods named Draw2 with a return type of string and with the parameter signature (Rect, string[,], int, int) was found in ….

Directly contradicting the previous error.

(Note that in the actual requirement, the string needs to look up other members, so does need to be non-static, even though in this toy example it doesn’t).

Comments (4)

  1. Tor Esa Vestergaard

    This issue is resolved in the final release version of 3.0 (not currently available, but will be soon) - if you would like a preview build with the feature included, please contact me on Discord :)

  2. Warwick Allison reporter
    • changed status to open

    Almost works in 3.0.0.4RC.

    The returned value doesn't seem to be honoured. It works if I use the matrix[,], int, int signature and force the matrix value to be written to.

  3. Warwick Allison reporter

    Specifically:

    using Sirenix.OdinInspector;
    using UnityEngine;
    
    public class TableMatrixTest : SerializedMonoBehaviour
    {
        [TableMatrix(DrawElementMethod ="DrawElement1")]
        public string[,] matrix;
    
        // The string never changes, despite being forceably changed (!!)
        string DrawElement1(Rect r, string s)
        {
            GUI.Label(r, s);
            return "XX";
        }
    
        // This however works.
        string DrawElement1B(Rect r, string s)
        {
            if (GUI.Button(r, s))
                return "XX";
            return s;
        }
    
        // This reveals why the above works.
        string DrawElement1C(Rect r, string s)
        {
            GUI.Label(r, s);
            GUI.changed = true;
            return "XX";
        }
    
        // A cleaner workaround: change the matrix directly.
        string DrawElement2(Rect r, string[,] m, int x, int y)
        {
            GUI.Label(r, m[x, y]);
            m[x, y] = "YY";
            return "YY";
        }
    
        [Button("Init")]
        void InitMatrix()
        {
            matrix = new string[2, 2];
            matrix[0, 0] = "00";
            matrix[1, 0] = "10";
            matrix[0, 1] = "01";
            matrix[1, 1] = "11";
        }
    
        [Button("Rand")]
        void RandMatrix()
        {
            matrix[Random.Range(0, matrix.GetLength(0)), Random.Range(0, matrix.GetLength(1))] = "ABCDEFGH".Substring(Random.Range(0, 6), 2);
        }
    }
    

  4. Log in to comment