Make Tool Script That Creates Additional Properties in the Editor

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By scrubswithnosleeves

Hi All,

I am trying to make something like a level editor that can be used in the editor. (I am making something for other developers). The idea is that you can select properties from the inspector and it will change the layout of a controller in real time.

I know You can use export variables + tool scripts to achieve something like this, but I want to be able to create additional properties depending on what the user/dev selected from those variables. For example, the user/dev selects “add button” from an export string var. I then want a new property to appear that will have a drop-down of (right, left, top, bottom) for the user to select the location of the button.

Any ideas on how to do this? Is a Tool script going to be enough, or is there more I need to do?

:bust_in_silhouette: Reply From: Wakatta

For what you’re trying to do i’d recommend using Editor plugins for more control

You can create whole menu structures using User Interface nodes and simply hide/show the controls based on the user/dev selections.

An example

Plugin Script

tool extends EditorPlugin

enum options {BOTTOM, LEFT, RIGHT, TOP}
var menu = preload("res://addons/Example/menu.tscn").instance()
var option_button = menu.get_node("OptionButton")
var add_button = menu.get_node("Button")

var last_position = CONTAINER_SPATIAL_EDITOR_BOTTOM

func _add_button_pressed():
    #add_button has Toggle mode enabled
	match add_button.pressed:
		true: 
			option_button.show()
			add_button.text = "Sub"
		false:
			option_button.hide()
			add_button.text = "Add"

func _option_button_pressed(index):
	remove_control_from_container(last_position, menu)
	match index:
		options.LEFT:
			last_position = CONTAINER_SPATIAL_EDITOR_SIDE_LEFT
		options.RIGHT:
			last_position = CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT
		options.TOP:
			last_position = CONTAINER_SPATIAL_EDITOR_MENU
		options.BOTTOM:
			last_position = CONTAINER_SPATIAL_EDITOR_BOTTOM
	add_control_to_container(last_position, menu)

func _enter_tree():
	#add control to editor CONTAINER_CANVAS_EDITOR for 2D SPATIAL for 3D
	add_control_to_container(CONTAINER_SPATIAL_EDITOR_BOTTOM, menu)
	
	add_button.connect("button_up", self, "_add_button_pressed")
	option_button.connect("item_selected", self,"_option_button_pressed")
	
	#poulate option node, can also be done through editor
	for item in options.keys():
		option_button.add_item(item)

func _exit_tree():
	remove_control_from_container(last_position, menu)

Menu.tscn
menu

Wakatta | 2021-01-15 13:07