-
-
Notifications
You must be signed in to change notification settings - Fork 574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using TypedArray with an enum causes 'get_class_static' is not a member of ... #1584
Comments
Does it work if you use |
I might be missing something but I don't seem to be able to use MAKE_TYPED_ARRAY_INFO. I tried to add it to the end of my Direction.hpp file after I also tried to add what would be result of the macro directly in the Direction.hpp file but I still get the same error #pragma once
namespace Game {
enum Direction {
Up,
Down,
Left,
Right
};
}
VARIANT_ENUM_CAST(Game::Direction)
namespace godot {
template<>
struct GetTypeInfo<TypedArray<Game::Direction>> {
static constexpr GDExtensionVariantType VARIANT_TYPE = GDEXTENSION_VARIANT_TYPE_ARRAY;
static constexpr GDExtensionClassMethodArgumentMetadata METADATA = GDEXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline PropertyInfo get_class_info() {
return make_property_info(Variant::Type::ARRAY,
"",
PROPERTY_HINT_ARRAY_TYPE,
Variant::get_type_name(Variant::INT).utf8().get_data());
}
};
template<>
struct GetTypeInfo<const TypedArray<Game::Direction>&> {
static constexpr GDExtensionVariantType VARIANT_TYPE = GDEXTENSION_VARIANT_TYPE_ARRAY;
static constexpr GDExtensionClassMethodArgumentMetadata METADATA = GDEXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline PropertyInfo get_class_info() {
return make_property_info(Variant::Type::ARRAY,
"",
PROPERTY_HINT_ARRAY_TYPE,
Variant::get_type_name(Variant::INT).utf8().get_data());
}
};
} |
It looks like it compiles to something that shows up in Godot as Edit: if I replace the |
@BenLubar Thanks, using both MAKE_TYPED_ARRAY(Game::Direction, godot::Variant::INT)
MAKE_TYPED_ARRAY_INFO(Game::Direction, godot::Variant::INT) As for showing up in Godot as ClassDB::bind_method(D_METHOD("set_sequence", "sequence"), SetSequence);
ClassDB::bind_method(D_METHOD("get_sequence"), GetSequence);
ADD_PROPERTY(
PropertyInfo(Variant::ARRAY, "sequence", PROPERTY_HINT_TYPE_STRING, String::num(Variant::INT) + "/"
+ String::num(PROPERTY_HINT_ENUM) + ":Up,Down,Left,Right"),
"set_sequence",
"get_sequence"); |
@ZacharieBeauchemin That seems about right to me! |
Ok for anyone stumbling here in the future and wondering why they can't use So unless someone has a better solution (which may well exist since I am quite new in C++ and gdextension in general) I ended up just copying the expanded macros like this: namespace godot {
// Expanded macro MAKE_TYPED_ARRAY(Game::Direction, godot::Variant::INT)
template<>
class TypedArray<Game::Direction> : public Array {
public:
_FORCE_INLINE_ void operator=(const Array& p_array) const {
ERR_FAIL_COND_MSG(!is_same_typed(p_array), "Cannot assign an array with a different element type.");
_ref(p_array);
}
_FORCE_INLINE_ TypedArray(const Variant& p_variant) : TypedArray(Array(p_variant)) {}
_FORCE_INLINE_ TypedArray(const Array& p_array) {
set_typed(Variant::INT, StringName(), Variant());
if (is_same_typed(p_array)) {
_ref(p_array);
} else {
assign(p_array);
}
}
_FORCE_INLINE_ TypedArray() {
set_typed(Variant::INT, StringName(), Variant());
}
};
// Expanded macro MAKE_TYPED_ARRAY_INFO(Game::Direction, godot::Variant::INT)
template<>
struct GetTypeInfo<TypedArray<Game::Direction>> {
static constexpr GDExtensionVariantType VARIANT_TYPE = GDEXTENSION_VARIANT_TYPE_ARRAY;
static constexpr GDExtensionClassMethodArgumentMetadata METADATA = GDEXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static PropertyInfo get_class_info() {
return make_property_info(
Variant::Type::ARRAY,
"",
PROPERTY_HINT_ARRAY_TYPE,
Variant::get_type_name(Variant::INT).utf8().get_data());
}
};
template<>
struct GetTypeInfo<const TypedArray<Game::Direction>&> {
static constexpr GDExtensionVariantType VARIANT_TYPE = GDEXTENSION_VARIANT_TYPE_ARRAY;
static constexpr GDExtensionClassMethodArgumentMetadata METADATA = GDEXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static PropertyInfo get_class_info() {
return make_property_info(
Variant::Type::ARRAY,
"",
PROPERTY_HINT_ARRAY_TYPE,
Variant::get_type_name(Variant::INT).utf8().get_data());
}
};
} Having to do this seems a bit weird to me but at least it works. |
Godot version
4.3
godot-cpp version
4.3
System information
Windows 11
Issue description
When creating a TypedArray the following error occurs:
Steps to reproduce
Create an enum like so:
Try to use it as the type for a TypedArray like so:
Minimal reproduction project
N/A
The text was updated successfully, but these errors were encountered: