GDExtension: exporting typed array with polymorphism

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Wormerer

I have a question about exporting typed arrays in GDExtension. What I want is to achieve in C++ is something along the lines of

@export var textures: Array[Texture]

or even

@export var my_elems: Array[MyBaseClassWithPossibleChildClasses]

I need to export it I think in _bind_methods() function, and the export requires providing the correct godot::PropertyInfo. I can’t figure out which parameters to use to export a typed array. Also, I want to use reference to an object which can be a different subclass of a base class.


More specific example: base class UserController, and descendants PlayerController, AiController, ReplayController etc. And the list of all possible controllers:

@export var controllers: Array[UserController]

which can contain any number of PlayerController, AiController, ReplayController instances.
It’s not the only case, there are other cases like that.

All the classes I want to be exported are derived from Resource class.


Is it possible to implement in Godot 4.0 beta 2? If not directly, are there any workarounds for this?

I am trying to do this currently, did you ever figure it out?

DaZel77 | 2023-03-22 19:38