Add a extra bottom menu item when reloading plugin instead of updating the same one

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

I have been playing around with editorplugin side of things. To be honest I am struggling
anyway I have the following code

tool
extends EditorPlugin

var a_panel = preload("res://addons/add_bottom_menu/bottom_test.tscn")
var a_new_control := Control.new()

    func _ready():
    	
    	#a_new_control = a_panel.instance()
    	add_control_to_bottom_panel(a_new_control,"My Plugin")
    	
    	var editor_viewport = get_editor_interface().get_editor_viewport()
    	yield(get_tree(), 'idle_frame')
    	a_new_control.rect_min_size.y = editor_viewport.rect_size.y * 0.35
    	
    	add_label()
    	add_button()
    
    
    
    func add_label():
    	var a_label = Label.new()
    	a_label.name = "Label"
    	a_label.margin_left = 20
    	a_label.margin_top = 20
    	a_label.text = "Test"
    	a_new_control.add_child(a_label)
    	
    func add_button():
    	var button = Button.new()
    	button.margin_left = 150
    	button.margin_top = 20
    	button.text = "Press Me"
    	a_new_control.add_child(button)
    	button.connect("button_down" ,self,"on_btn_toggled")
    	
    
    func on_btn_toggled():
    	a_new_control.get_node("Label").text = "Clicked"

The code itself works except whenever I made changes to the script I need to de-activate plugin and the reactivate it. And instead of overwrting whatever was already existing at the bottom menu, it would add another one . I am not sure how to remove existing bottom menu item when I de-activate it.

:bust_in_silhouette: Reply From: Dlean Jeans

Add this to your code:

func _exit_tree():
	a_new_control.queue_free()

Sorry, I am not sure what I did wrong. But It is not working.

lowpolygon | 2020-01-10 11:30