Custom inspector, cant edit variables in subclass

So i used a tutorial on how to create a custom inspector because i’m making a farm game and i wanted to make an easier way to create orders for an order board so i have it to where when i press a button on the inspector it adds a Element to a list and under the Elements are multiple variables

public class OrderAction : MonoBehaviour {

    //MyClass myclass;
    materialss material;

    public List<materialss> materials = new List<materialss>();

    [System.Serializable]
    public class materialss
    {

        public string MaterialName = string.Empty;
        public int amountNeeded;
        public Image materialImage;
        public Text amountNeededT;

        public void Update()
        {
            Debug.Log("Done");
            materialImage.sprite = Resources.Load(MaterialName) as Sprite;
        }
    }
}

This is the script for controlling the orders

[CustomEditor(typeof(OrderAction))]
public class OrderEditor : Editor
{

    OrderAction t;
    SerializedObject GetTarget;
    SerializedProperty thisList;

    void OnEnable()
    {
        t = (OrderAction)target;
        GetTarget = new SerializedObject(t);
        thisList = GetTarget.FindProperty("materials");
    }

    public override void OnInspectorGUI()
    {
        OrderAction myOrderAction = (OrderAction)target;

        GetTarget.Update();

        //myOrderAction.experience = EditorGUILayout.IntField("Experience", myOrderAction.experience);
        GUILayout.Label("List of materials");
        GUILayout.Space(20);
        if (GUILayout.Button("Add Material"))
        {
            t.materials.Add(new OrderAction.materialss());
            Debug.Log("Added");
        }

        base.OnInspectorGUI();
    }

    public void addMaterial()
    {
        OrderAction myOrderAction = (OrderAction)target;
       
        myOrderAction.materials.Add(new OrderAction.materialss());
        Debug.Log("Added");
    }

}

This is the script that edits the inspector

Now the problem is in the OrderAction script i have a subclass called materialss. When the button is pressed it creates a new element using the variables in the subclass and it creates the new elements fine but i cant seem to be able to edit them. for example I have the Update function and im trying to get the image for the material to change to a sprite according to the name and it doesn’t work. i put a Debug.Log in and it doesn’t even call that. So how would i be able to edit the variables or can i?

First of all you’re mixing to different concepts how custom inspectors can be implemented. You could drop your SerializedObject / SerializedProperty as you don’t use it at all.

When using the “target” property you’re dealing with your object directly. However that means you have to take care of telling the editor when things have changed so the editor actually uptates the serialized data. This is usually done by using Undo.RecordObject right before you change anything.

So it would look like this:

[CustomEditor(typeof(OrderAction))]
public class OrderEditor : Editor
{
    OrderAction t;
    void OnEnable()
    {
        t = (OrderAction)target;
    }
    public override void OnInspectorGUI()
    {
        if (GUILayout.Button("Add Material"))
        {
            Undo.RecordObject(t, "Add new material");
            t.materials.Add(new OrderAction.materialss());
        }
        base.OnInspectorGUI();
    }
}