Need help with plugin that automatically unfolds resources and arrays

Godot Version

4.6

Question

Working with nested Resources and Arrays in the Inspector can be cumbersome because you have to manually unfold each entry.

I want to create an EditorPlugin that unfolds / toggles specific Resources and Arrays in the Inspector by default to see how it could improve my workflow.

The toggle mode of the Array and Resource buttons is set to true and the signal gets emitted but my code isn’t working.

What am I missing here?

@tool
extends EditorPlugin

var editor_inspector: EditorInspector

func _enter_tree() -> void:
	editor_inspector = EditorInterface.get_inspector()
	editor_inspector.edited_object_changed.connect(_on_editor_inspector_edited_object_changed)


func _exit_tree() -> void:
	if editor_inspector.edited_object_changed.is_connected(_on_editor_inspector_edited_object_changed):
		editor_inspector.edited_object_changed.disconnect(_on_editor_inspector_edited_object_changed)
	editor_inspector = null


func _on_editor_inspector_edited_object_changed() -> void:
	_unfold_all.call_deferred()


func _unfold_all() -> void:
	var edited_object := editor_inspector.get_edited_object()

	var stack: Array[Node] = editor_inspector.get_children()

	while not stack.is_empty():
		var node: Node = stack.pop_back()
		stack.append_array(node.get_children())
		
		if node is Button:
			if node.text.begins_with("Array[") and node.text.contains("(size"):
				node.toggled.emit.call_deferred()

			if node.text.ends_with(".tres"):
				node.toggled.emit.call_deferred()

I looked into relevant signal connections of those buttons and it appears that only pressed is connected. So try emitting that instead of toggled.

Pressed works better, but it’s still not very reliable. Closing this and going to use CSV data instead of Resources. Thanks though!

No, It’s totally doable. There’s a little catch, though.

If you look the name of the function connected to the pressed signal it’s EditorPropertyArray::_edit_pressed (or equivalent for dictionary properties). This is not exposed to scripting but looking it up in the source code:

You can see that it weirdly relies on button’s button_pressed property. So the catch is to set this to true/false (depending if you want to fold/unfold) and then force-emit the pressed signal.

It works quite well actually.

That said, if you have a lot of data to manage, CSV still might be a wiser choice than fiddling with the inspector.