How to display a custom list similar to Array in editing?

Godot Version

4.3

Question

I would like to create a list in the inspector that behaves like an Array, such as the Items of the OptionButton node in the inspector。

And I also hope to create using GDExtension. I tried reading the source code of OptionButton, but I couldn’t fully understand it.

2 Likes

If you want to just create a property for a node, you can do it using GDScript. Just expose an Array property with @export and it will act in a similar way.

If you want to have it “typed”, showing specific fields for every item in the array and not allow the editor to insert any type of object in it, you can do so by creating a custom class and assigning the type to the array.

1 Like

I hope to be able to easily delete or add an item, but TypeArray can only be created quickly and cannot specify the deletion of a certain item. I don’t mind reading more code to implement functions similar to those in OptionButton, but I can’t find the code or documentation to implement the checker function.And I will ultimately use CPP implementation in gdextension

1 Like

Hello, you can create an inspector plugin to have this type of behavior.
You can then add your own properties editor as described here.
This approach allows you to reproduce or adapt the behavior of Godot’s internal property editors, although it’s not always possible to reuse these directly as they are mostly internal to the editor.

Other helpful resource: GDExtension C++ example — Godot Engine (stable) documentation in English

Excuse me again, after checking the EditPlugin, EditInspectorPlugin, and EditProperty, I couldn’t find any information about adjusting the order of items.
I also read the source code for ‘property list helper’ in the source code, but I couldn’t find any code related to binding.
I have found that there are a large number of structures in Godot that have Item items similar to those in OptionButton in the checker, such as Array, Dictionary, and the behavior of OptionButton in the checker. I am wondering if this is a structure that exists in Godot and can be called directly?

Hello, sorry for the delayed response. I’ve been offline for the past few days.

I’m not aware of a built-in structure in Godot that lets you directly adjust the order of items or their binding behavior. If you need to modify the order or binding behavior, you can implement this feature yourself.

For instance, you could create an EditorProperty to handle each item individually. By storing your items’ data in an Array, you can then use the Array’s methods (such as sort_custom(), insert(), or map()) to reorder the data and thus update the displayed items accordingly.

1 Like