Iusse about add_option with @tool

Godot Version

4.3

Question


I am extending the original FileDialog using add_option. I used @tool because I am trying to create a plugin. A part of the code looks like this:

@tool

extends FileDialog
class_name CreateComponentDialog

var extend_options = ["Custom Host Type", "Built-in Host Type"]
var editor_plugin: EditorPlugin
var editor_interface: EditorInterface

func _ready() -> void:
	add_option("Create Group Node", [], 0)
	add_option("Inherit From", extend_options, 0)
	add_filter("*.gd", "Script Component")
	add_filter("*.tscn", "Scene Component")

There is also a .tscn file, part of which looks like this:

[node name="CreateComponentDialog" type="FileDialog"]
title = "Create Component"
initial_position = 2
size = Vector2i(800, 600)
visible = true
filters = PackedStringArray("*.gd ; Script Component", "*.tscn ; Scene Component")
option_count = 2
option_0/name = "Create Group Node"
option_1/name = "Inherit From"
option_1/values = PackedStringArray("Custom Host Type", "Built-in Host Type")

After switching to this scene and selecting “Reload Project”(much times) from the menu, something strange happened:

[node name="CreateComponentDialog" type="FileDialog"]
title = "Create Component"
initial_position = 2
size = Vector2i(800, 600)
visible = true
filters = PackedStringArray("*.gd ; Script Component", "*.tscn ; Scene Component", "*.gd ; Script Component", "*.tscn ; Scene Component", "*.gd ; Script Component", "*.tscn ; Scene Component", "*.gd ; Script Component", "*.tscn ; Scene Component", "*.gd ; Script Component", "*.tscn ; Scene Component")
option_count = 10
option_0/name = "Create Group Node"
option_1/name = "Inherit From"
option_1/values = PackedStringArray("Custom Host Type", "Built-in Host Type")
option_2/name = "Create Group Node"
option_3/name = "Inherit From"
option_3/values = PackedStringArray("Custom Host Type", "Built-in Host Type")
option_4/name = "Create Group Node"
option_5/name = "Inherit From"
option_5/values = PackedStringArray("Custom Host Type", "Built-in Host Type")
option_6/name = "Create Group Node"
option_7/name = "Inherit From"
option_7/values = PackedStringArray("Custom Host Type", "Built-in Host Type")
option_8/name = "Create Group Node"
option_9/name = "Inherit From"
option_9/values = PackedStringArray("Custom Host Type", "Built-in Host Type")
script = ExtResource("1_2thst")

Many duplicate elements appear in my interface. Is this expected behavior? The code written in the script seems to have a permanent effect on the .tscn file.