Description
Godot version
4.2-dev (f880892c3)
godot-cpp version
4.2-dev (749b0b9)
System information
Windows 11 (10.0.22621)
Issue description
In Godot itself you have the ability to bind a property with what's called an "index", which essentially just binds an integer (usually an enum value) to the property that will always be passed in as the first argument to its getter and setter functions. You typically do this using the ADD_PROPERTYI
macro, as seen here.
In godot-cpp there is an index parameter for ClassDB::add_property
, but it seems that it's currently being discarded completely, along with the rest of the (seemingly unused) PropertySetGet
struct, as seen here. As far as I can tell this has been the case for as long as GDExtension has been a thing.
Since the index is being discarded currently, it gets the default value of -1
and leads to the binding of the property emitting errors saying ERROR: Invalid function for setter 'MyNode::my_setter for property 'my_property'.
The only workaround is to not use indexed properties, and instead create and bind a bespoke setter/getter method for each property.
Steps to reproduce
Add (and register) the following class in an extension of your choosing:
class MyNode : public Node {
GDCLASS(MyNode, Node)
void my_setter(int32_t p_index, real_t p_value) { }
real_t my_getter(int32_t p_index) const { return 21.0f; }
static void _bind_methods() {
ClassDB::bind_method(D_METHOD("my_setter", "index", "value"), &MyNode::my_setter);
ClassDB::bind_method(D_METHOD("my_getter", "index"), &MyNode::my_getter);
ClassDB::add_property(get_class_static(), PropertyInfo(Variant::FLOAT, "my_property"), "my_setter", "my_getter", 42);
}
};
... and then run Godot from within a terminal/console, since the error message is only emitted into stderr when starting the editor, which should look something like this:
ERROR: Invalid function for setter 'MyNode::my_setter for property 'my_property'.
at: (core\object\class_db.cpp:980)
Minimal reproduction project
N/A