|Topic was automatically imported from the old Question2Answer platform.
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
my_dynamic_var = v
And use it like this
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?