Topic was automatically imported from the old Question2Answer platform.
Asked By
MikeMikeMike
Hi…,
how to add by a tool script a new string to my export var?
tool
extends Node
export(String, "Rebecca", "Mary", "Leah") var character_name
func _ready():
if Engine.editor_hint:
# how to add by script a fourth value "Sandy" to the character_name list?
You can’t add a string this way. If you use export, the list of values will be fixed.
If you want the list of values to be dynamic, there are at least two ways I can think of, but they will require a lot more work:
Way 1: _get_properties_list
Instead of using export, override _get_properties_list so you can generate and return export options manually. This means you can run any code you want to output the array of strings you want shown.
If the array needs to change, you may then call property_list_changed() to tell Godot to update the inspector.
func _get_property_list() -> Array:
return [
{
"name": "character_name",
"type": TYPE_STRING,
"usage": PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE,
"hint_string": "16, 32" # <-- your list of strings
}
]
Way 2: EditorInspectorPlugin
This is more involved but the idea is that you can completely override the GUI of the inspector for that specific property. I don’t have time for an example but I mention this anyways for completeness. Although this could open the possibility for a plugin to add support for dynamic dropdowns in a generic way.
See documentation: Inspector plugins — Godot Engine (stable) documentation in English
hi @Zylann, thank you for your detailed answer. This looks advanced, I will take a look. Thanks again, Mike