0 votes

Usually one exports a property with an explicit type, like in

export(String) var my_string

or the type can be infered if the property is strongly typed, like in

export var my_string:String

But what if I want to choose the property type in the inspector itself, the same way it can be done with array items and dictionary keys and values? I'm talking about that pencil icon that lets you chose a variant type for the value that will be input.

I'm pretty sure this is impossible out-of-the-box and currently, when I want an exported property with a choosable type, I just wrap it inside an array.

export(Array) var my_dynamic_var = [null] setget set_my_dynamic_var, get_my_dynamic_var
func set_my_dynamic_var(v):
    my_dynamic_var[0] = v
func get_my_dynamic_var():
    return my_dynamic_var[0]

And use it like this

func _ready():
    print(self.my_dynamic_var) # prints null
    self.my_dynamic_var = 98
    print(self.my_dynamic_var) # prints 98

But it must be possible by other means since there is already support for it (in arrays and dictionaries).

So my question is: By which means I could achieve a dynamic export? Could it be done just with a tool script? Or could it be done with a gdscript editor plugin? Or would I need to make changes to the engine itself?

The previous mentions where in order of simplicity. Just doing something inside a tool script would be the easiest solution if this where possible. If not, doing an editor plugin in gdscript is also fairly simple but not so much as writing some logic in a tool script. And by far changing the engine would be the most work of all, but it would certainly be possible.

So, anyone out there has already done anything like this? Or have any hint of where to look at to do this?

Godot version 3.4.2
in Engine by (265 points)

Please log in or register to answer this question.

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 Frequently asked questions and 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.