Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity How to remove the elements label (Element 0 - Element ...) in a array in the inspector

In my editor for one of my scripts I am trying to figure out how to remove what is in the red box (Element 0 - Element 14) so basically you would just see the string inputs.

enter image description here

My Editor Script so far :

[CustomEditor(typeof(Change))]
public class Change_Editor : Editor {

    public override void OnInspectorGUI(){

    // Grab the script.
    Change myTarget = target as Change;
    // Set the indentLevel to 0 as default (no indent).
    EditorGUI.indentLevel = 0;
    // Update
    serializedObject.Update();

    EditorGUILayout.BeginHorizontal();


    EditorGUILayout.BeginVertical();
    EditorGUILayout.PropertyField(serializedObject.FindProperty("SceneNames"), true);
    EditorGUILayout.EndVertical();


    EditorGUILayout.EndHorizontal();


    // Apply.
    serializedObject.ApplyModifiedProperties();
    }
}

EDIT : MotoSV's answer worked and the result is shown below.

enter image description here

like image 754
JoeyL Avatar asked Oct 15 '25 09:10

JoeyL


1 Answers

To show just the value of each array index you simply have to enumerate through the array and display a field just for the value:

[CustomEditor(typeof(Change))]
public class Change_Editor : Editor
{
    public override void OnInspectorGUI()
    {
        // Grab the script.
        Change myTarget = target as Change;
        // Set the indentLevel to 0 as default (no indent).
        EditorGUI.indentLevel = 0;
        // Update
        serializedObject.Update();

        EditorGUILayout.BeginHorizontal();

        EditorGUILayout.BeginVertical();

        //  >>> THIS PART RENDERS THE ARRAY
        SerializedProperty sceneNames = this.serializedObject.FindProperty("SceneNames");
        EditorGUILayout.PropertyField(sceneNames.FindPropertyRelative("Array.size"));

        for(int i = 0; i < sceneNames.arraySize; i++)
        {
            EditorGUILayout.PropertyField(sceneNames.GetArrayElementAtIndex(i), GUIContent.none);
        }
        //  >>>

        EditorGUILayout.EndVertical();

        EditorGUILayout.EndHorizontal();

        // Apply.
        serializedObject.ApplyModifiedProperties();
    }
}

I have not fully tested this, i.e. saved a scene, loaded up and verified all fields are serialized, but the look in the inspector seems to match what you're after.

like image 193
MotoSV Avatar answered Oct 16 '25 21:10

MotoSV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!