So… I’ve been experimenting a bit and i finally figured it out.
Here is how to expose and array of Ref<WhateverRefCounted> as a property of a node/resource.
namespace godot {
MAKE_TYPED_ARRAY(Ref<Image>, Variant::OBJECT)
MAKE_TYPED_ARRAY_INFO(Ref<Image>, Variant::OBJECT)
class ImageCollection : public Resource {
GDCLASS(ImageCollection, Resource)
private:
TypedArray<Ref<Image>> m_images;
public:
void set_images(TypedArray<Ref<Image>> p_images)
{
m_images = p_images;
}
TypedArray<Ref<Image>> get_images() const
{
return m_images;
}
protected:
static void _bind_methods()
{
ClassDB::bind_method(D_METHOD("set_images", "images"), &ImageCollection::set_images);
ClassDB::bind_method(D_METHOD("get_images"), &ImageCollection::get_images);
ADD_PROPERTY(
PropertyInfo(
Variant::ARRAY,
"images",
PROPERTY_HINT_TYPE_STRING,
String::num(Variant::OBJECT) + "/" + String::num(PROPERTY_HINT_RESOURCE_TYPE) + "Image"
),
"set_images",
"get_images"
);
}
};
}
- Use the
MAKE_TYPED_ARRAY
andMAKE_TYPED_ARRAY_INFO
macros with your Ref<Whatever> as first parameter andVariant::OBJECT
for the second parameter. To avoid re-declarations I suggest doing this in a separate file since this macros declare new types. - Use TypedArrays (not Vector like i did in my first example).
- Do not pass values to the setters by reference, only by value.
- When binding your property, in the PropertyInfo use
PROPERTY_HINT_TYPE_STRING
as property hint and for the hint string passString::num(Variant::OBJECT) + "/" + String::num(PROPERTY_HINT_RESOURCE_TYPE) + "Image"
with the intended resource type instead of “Image” (source: this post)
I tested this a lil bit and it seems to function as it should, I hope your PC doesn’t explode because of me.
I hope to have been helpfull.