How to set up a TypedArray with a custom type in GDExtension

gd_ta_fixed

I finally figured it out! I went down so many rabbit holes, but of course the solution was simple. As it turns out, in my attempt to write a simple test case, I didn’t used the appropriate PropertyHint.

The following solved it:

void TypedArrayTest::_bind_methods() {
    //...

    ClassDB::add_property(
        "TypedArrayTest", 
        PropertyInfo(
            Variant::ARRAY, 
            "test_array", 
            PROPERTY_HINT_TYPE_STRING, 
            String::num(Variant::OBJECT) + "/" + String::num(PROPERTY_HINT_RESOURCE_TYPE) + ":TestObject"
        ), 
        "set_test_array", 
        "get_test_array"
    );
    
}

It had been staring me in the face this whole time, straight from the Godot docs: @GlobalScope — Godot Engine (stable) documentation in English

Instead of using PROPERTY_HINT_TYPE_STRING I tried to use PROPERTY_HINT_ARRAY_TYPE as well, but I couldn’t get that to work. Maybe this one only works with built in types, I’m not sure.