0 votes

In gdscript you can do it by export param:

export (String, "Rebecca", "Mary", "Leah") var character_name

How to do it in c++ gdnative? Is it possible to select value not from constant list of strings but from dynamic array of strings?

Godot version latest
in Engine by (267 points)

1 Answer

0 votes

With latest (currently 4.0 alpha 7) you can export a choice of strings by using PROPERTY_HINT_ENUM:

ADD_PROPERTY(PropertyInfo(Variant::STRING, "character_name", godot::PROPERTY_HINT_ENUM, "Mary,Rebecca,Leah"), "set_character_name", "get_character_name");

Concerning the second part, I don't believe that modifying the choice list is currently possible with extensions - only with module development. The reason is that Object::_validate_property is not available to extensions. See this discussion

by (272 points)

Will it work with 3.x? I need to collect all available input commands and then select from that array with dropbox.

It doesn't seem that exporting enums is possible in 3.x. See this discussion.

You might be better off creating a string parameter in GDNative and building a wrapper in GDScript to provide an enum. Though that doesn't help with dynamically populating items.

For dynamic population I think you're limited to writing a proper module for now. Check out the source for AudioStreamPlayer, which modifies it's bus enum parameter when an audio bus is added or removed.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.