Hello! I’m making an inspector plugin for myself. But I’m missing something.
Recall the control that appears when you use @export on a Node var, as of Godot 4. You get an Assign... button that brings up a window, which allows you to select a node from your scene tree. Super convenient!
My plugin would like to replicate that functionality elsewhere… but I don’t know how to do that.
Is there a function somewhere that creates that specific button, plus the subsequent prompt? Am I missing a very obvious Control somewhere? Should I instead recreate it by hand?
All the Controls the editor uses are the same you get in the Create New Node dialog. They really mean it when they say the editor is just a Godot game.
You can look at the source code to know how anything is implemented and replicate it. For example, the NodePath property editor is created in the below code. It’s just a HBoxContainer with a Button with text and a MenuButton for the side menu.
Then the node selection popup is created here and so on.
You can get that tree dots icon of the MenuButton’s icon from the editor theme like this:
var theme = EditorInterface.get_editor_theme()
var icon = theme.get_icon("GuiTabMenuHl", "EditorIcons")
You can even discover the path to one visible in the inspector using the class’s name so you can edit its behavior.
@tool
extends EditorScript
func _run():
var inspector = EditorInterface.get_inspector()
var nodepath_editor_path = search_native_node(inspector, "EditorPropertyNodePath")
var editor = inspector.get_node(nodepath_editor_path) as EditorProperty
editor.modulate = Color.FIREBRICK
func search_native_node(node:Node, name:String):
var path = str(node.get_path())
if (path.contains(name)):
return path
for child in node.get_children():
var result = search_native_node(child, name)
if result:
return result
return null
+1 I wish this had built-in support. We have things like ColorPicker, EditorResourcePicker, and EditorScriptPicker. Would be very handy to also have some EditorNodePicker that I could easily embed into my editor plugin without having to reimplement Godot source code. Doesn’t seem like EditorPropertyNodePath is accessible from my scripts.