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
}
]
(note, I adapted this from code that used TYPE_INT
instead, so I don't know if it is exact)
See documentation: https://docs.godotengine.org/en/stable/classes/class_object.html#class-object-method-get-property-list
See also this similar question: https://godotengine.org/qa/78795/is-possible-set-append-type-in-_get_property_list-as-enum?show=78795#q78795
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: https://docs.godotengine.org/en/stable/tutorials/plugins/editor/inspector_plugins.html