Skip to content

Instantly share code, notes, and snippets.

@zledas
Last active November 6, 2026 15:30
Show Gist options
  • Select an option

  • Save zledas/8e7583b8a2146cade84246bb7dfd7fca to your computer and use it in GitHub Desktop.

Select an option

Save zledas/8e7583b8a2146cade84246bb7dfd7fca to your computer and use it in GitHub Desktop.
Set custom max height for editor lists in Unity versions that use `UIElements`

Set custom max height for editor lists in Unity versions that use UIElements

The default Unity editor list max-height value is 520px and it is quite annoying if you have long lists and no other serialized properties on the object. Use this to change this max-height value for each list individually.

You need to put ListMaxHeightPropertyDrawer.cs in Editor folder.

No external dependencies.

Examples

Just add [ListMaxHeight(<max-height>)] attribute to list or array field.

// This sets `max-height` to 800px.
[ListMaxHeight(800)]
public List<int> listOfNumbers;

// This sets `max-height` to `int.MaxValue` and makes it virtually unlimited.
[ListMaxHeight]
public List<string> listOfStrings;

License

MIT No Attribution

Copyright 2026 Žilvinas Ledas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// MIT No Attribution
//
// Copyright 2026 Žilvinas Ledas
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using UnityEngine;
[System.AttributeUsage(System.AttributeTargets.Field, Inherited = false)]
public class ListMaxHeightAttribute: PropertyAttribute {
public int maxHeight;
public ListMaxHeightAttribute(int maxHeight = int.MaxValue): base(true) {
this.maxHeight = maxHeight;
}
}
// MIT No Attribution
//
// Copyright 2026 Žilvinas Ledas
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace tojPlugin {
[CustomPropertyDrawer(typeof(ListMaxHeightAttribute))]
public class ListMaxHeightPropertyDrawer: PropertyDrawer {
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
// The height for the property is just whatever Unity would do by default.
float propertyHeight = EditorGUI.GetPropertyHeight(property, label, true);
return propertyHeight;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
EditorGUI.PropertyField(position, property, label, true);
}
public override VisualElement CreatePropertyGUI(SerializedProperty property) {
ListMaxHeightAttribute listMaxHeightAttribute = (ListMaxHeightAttribute)this.attribute;
var propertyField = new PropertyField(property);
var propertyFieldCopy = propertyField;
propertyFieldCopy.schedule.Execute(
(TimerState obj) => {
for (int i = 0; i < propertyFieldCopy.hierarchy.childCount; i++) {
if (propertyFieldCopy.hierarchy[i].GetType() == typeof(ListView)) {
propertyFieldCopy.hierarchy[i].style.maxHeight = listMaxHeightAttribute.maxHeight;
}
}
}
);
return propertyField;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment