Unable to change list size in custom inspector

This just happened tonight and is really weird: The issue only exist in Normal(Inspector) Mode, In Debug I can edit everything.

I duplicated a CircleCaster script to make a variation (BoxCaster), and suddenly I can’t apply change on any Size int field (reset to existing value after pressing Enter) of List Property Fields in its custom editor while other fields works normally.

I can confirm that all the SerializedProperty is found correctly.

Have someone encountered this before?

    public override void OnInspectorGUI()
    {
        BoxCaster caster = (BoxCaster)target;
     
        GUILayout.BeginVertical();
            EditorGUILayout.PropertyField(LayerMaskProp);
            caster.CastSize = EditorGUILayout.Vector2Field("Size", caster.CastSize);
            caster.MaxCandidate = EditorGUILayout.IntField("Max Candidates", caster.MaxCandidate);

            GUILayout.BeginVertical("Box");
            caster.UseDepthLimit = EditorGUILayout.Toggle("Use Depth Limit", caster.UseDepthLimit);
            if (caster.UseDepthLimit) {
                GUILayout.BeginHorizontal();             
                    GUILayout.Label("Depth");
                    GUILayout.FlexibleSpace(); 
                    GUILayout.Label("Min", GUILayout.Width(32));     
                    caster.MinDepth = EditorGUILayout.FloatField(caster.MinDepth, GUILayout.Width(40));
                    GUILayout.Space(12);
                    GUILayout.Label("Max", GUILayout.Width(32)); 
                    caster.MaxDepth = EditorGUILayout.FloatField(caster.MaxDepth, GUILayout.Width(40));
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();         

            GUILayout.BeginVertical("Box");
                caster.OnlyTarget = EditorGUILayout.Toggle("Ignore non-targets (Tags)", caster.OnlyTarget);
                GUILayout.BeginHorizontal();             
                    GUILayout.Space(14);
                    EditorGUILayout.PropertyField(TargetTagsListProp, true);             
                GUILayout.EndHorizontal();             
                if (caster.OnlyTarget) {
                    GUILayout.BeginHorizontal();             
                        GUILayout.Space(14);
                        EditorGUILayout.PropertyField(BlackTagsListProp, true);         
                    GUILayout.EndHorizontal();         
                }
                GUILayout.BeginHorizontal();             
                    GUILayout.Space(14);
                    EditorGUILayout.PropertyField(BlackColListProp, true);                 
                GUILayout.EndHorizontal();             
            GUILayout.EndVertical();
        GUILayout.EndVertical();     
    }

I’m not seeing an ApplyModifiedProperties() anywhere.

SerializedObjects are just proxies to the real object. so the data you put into a SerializedObject(or SerializedProperty) doesn’t pass off to the real object until you call ApplyModifiedProperties.

on that same token if data changes on the object the SerializedObject needs to be notified. calling serializedObject.Update() will tell the Serialized object to check for changes that happened on the target object and then load that data into the serializedObject and its properties.

2 Likes

Whoa, this is first time I hear of this method… thanks! It works! :smile: