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()