creating an editor plugin script looks something like this:
@tool
extends EditorPlugin
var dock
func _enter_tree():
# Initialization of the plugin goes here.
# Load the dock scene and instantiate it.
dock = preload("res://addons/my_custom_dock/my_dock.tscn").instantiate()
# Add the loaded scene to the docks.
add_control_to_dock(DOCK_SLOT_LEFT_UL, dock)
func _exit_tree():
# Remove the dock.
remove_control_from_docks(dock)
dock.free()
with my_dock.tscn being UI elements (buttons, labels, spinbox, etc).
what I am looking for is an “object field”, but I cant find such a control.
in the inspector, it looks like this:
in this case, I have added a Json object into the inspector field. but can be a script, scene or other type of objects. we can drag them in or click and select “load” or wtv.
how do I add this type of control in a editor plugin?
#editor plugin script
@tool
extends EditorPlugin
var dock #Editor Plugin dock UI
#editor plugin is created##########
func _enter_tree():
# create UI containter
var area = VBoxContainer.new()
area.name = "myEditorPlugin"
# Pack UI into scene
var scene = PackedScene.new()
scene.pack(area)
# instantiate scene and add it to dock UI
dock = scene.instantiate()
var objectField = EditorResourcePicker.new()
#objectField.base_type = "JSON" #if you want to add a JSON object as resource
#objectField.base_type = "CompressedTexture2D" #if you want to add texture as resource
#objectField.base_type = "Node3D" #if you want to add Node3D as resource
#objectField.base_type = "Whatever" #you get the idea, you can limit any type of class as the object you want to add as resource
#add the UI element to the Editor Plugin dock
dock.add_child( get_UI() )
# Add the editor plugin UI to the docks (Upper Left dock in this case)
add_control_to_dock(DOCK_SLOT_RIGHT_UL, dock)
#editor plugin is closed##########
func _exit_tree():
# Remove the scene from the docks:
if(dock != null ):
remove_control_from_docks(dock)
dock.free()