Godot Version
4.2.1
Question
I binded a property with resource typed array and it works fine in the inspector like below.
However, when I launch the game, the value in the second item is wrong and behaves like an undefined value.
The KeyBinding class is below.
class KeyBinding : public godot::Resource {
GDCPP_REQUIRE_BINDING(KeyBinding, godot::Resource);
GDCPP_PROPERTY("LeftStick,RightStick,LeftStickButton,RightStickButton,Up,Down,Left,Right,A,B,X,Y,LB,RB,LT,RT,Start,Select", PROPERTY_HINT_ENUM, key, get_key, set_key, INT, PROPERTY_USAGE_DEFAULT)
GDCPP_PROPERTY("Pressed,Just Pressed,Just Released", PROPERTY_HINT_ENUM, operation, get_operation, set_operation, INT, PROPERTY_USAGE_DEFAULT)
GDCPP_PROPERTY("", PROPERTY_HINT_NONE, state_id, get_state_id, set_state_id, INT, PROPERTY_USAGE_DEFAULT)
GDCPP_PROPERTY("", PROPERTY_HINT_NONE, queue_action, is_queue_action, set_queue_action, BOOL, PROPERTY_USAGE_DEFAULT)
public:
GDCPP_METHOD(get_key)
BindingKeyTypes key() const { return _key; }
GDCPP_METHOD(set_key)
void setKey(BindingKeyTypes key) { _key = key; }
GDCPP_METHOD(get_operation)
BindingOperations operation() const { return _operation; }
GDCPP_METHOD(set_operation)
void setOperation(BindingOperations operation) { _operation = operation; }
GDCPP_METHOD(get_state_id)
s32 stateId() const { return _stateId; }
GDCPP_METHOD(set_state_id)
void setStateId(s32 stateId) { _stateId = stateId; }
GDCPP_METHOD(is_queue_action)
bool isQueueAction() const { return _queueAction; }
GDCPP_METHOD(set_queue_action)
void setQueueAction(bool queueAction) { _queueAction = queueAction; }
private:
BindingKeyTypes _key = BindingKey_LeftStick;
BindingOperations _operation = BindingOperation_Pressed;
s32 _stateId = -1;
bool _queueAction = false;
};
VARIANT_ENUM_CAST(gameplay::BindingKeyTypes);
VARIANT_ENUM_CAST(gameplay::BindingOperations);
The bind method is below.
void KeyBinding::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_key"), &KeyBinding::key);
ClassDB::bind_method(D_METHOD("set_key", "key"), &KeyBinding::setKey);
ClassDB::bind_method(D_METHOD("get_operation"), &KeyBinding::operation);
ClassDB::bind_method(D_METHOD("set_operation", "operation"), &KeyBinding::setOperation);
ClassDB::bind_method(D_METHOD("get_state_id"), &KeyBinding::stateId);
ClassDB::bind_method(D_METHOD("set_state_id", "stateId"), &KeyBinding::setStateId);
ClassDB::bind_method(D_METHOD("is_queue_action"), &KeyBinding::isQueueAction);
ClassDB::bind_method(D_METHOD("set_queue_action", "queueAction"), &KeyBinding::setQueueAction);
ClassDB::add_property(get_class_static(), PropertyInfo(Variant::INT, "key", PROPERTY_HINT_ENUM, "LeftStick,RightStick,LeftStickButton,RightStickButton,Up,Down,Left,Right,A,B,X,Y,LB,RB,LT,RT,Start,Select", PROPERTY_USAGE_DEFAULT), "set_key", "get_key");
ClassDB::add_property(get_class_static(), PropertyInfo(Variant::INT, "operation", PROPERTY_HINT_ENUM, "Pressed,Just Pressed,Just Released", PROPERTY_USAGE_DEFAULT), "set_operation", "get_operation");
ClassDB::add_property(get_class_static(), PropertyInfo(Variant::INT, "state_id", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT), "set_state_id", "get_state_id");
ClassDB::add_property(get_class_static(), PropertyInfo(Variant::BOOL, "queue_action", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT), "set_queue_action", "is_queue_action");
}
The debugging info is below.
The info shown in the picture is the second item in my resource array.
I don’t know why the enum value is like an undefined value, but I am sure that I modify it correctly in the inspector.
Any suggestion will be appreciated. Thanks.
Sorry, I forgot to put the enum definitions, I put them below.
enum BindingKeyTypes {
BindingKey_LeftStick,
BindingKey_RightStick,
BindingKey_LeftStickButton,
BindingKey_RightStickButton,
BindingKey_Up,
BindingKey_Down,
BindingKey_Left,
BindingKey_Right,
BindingKey_A,
BindingKey_B,
BindingKey_X,
BindingKey_Y,
BindingKey_LB,
BindingKey_RB,
BindingKey_LT,
BindingKey_RT,
BindingKey_Start,
BindingKey_Select,
};
enum BindingOperations {
BindingOperation_Pressed,
BindingOperation_Just_Pressed,
BindingOperation_Just_Released,
};
Note: It sometimes behaves correct, but after a bunch of relaunch of my editor, it suddenly occurs.