godot-cpp
godot-cpp copied to clipboard
Add `is_class_static` virtual method to GDCLASS macro.
Link to proposal: https://github.com/godotengine/godot-proposals/issues/8852
In the godot-cpp, we already have get_class_static() added by GDCLASS macro. Having also an instance method virtual bool is_class_static(StringName cn) would provide an efficient comparison method to the already existing functionality.
Usage
Ref<MyBaseclass> ref = get_my_class(); // returns Ref<MySubclass>;
if (ref->is_class_static(MySubclass::get_class_static()) {
// ...
}
Thanks!
However, as I wrote on the proposal: one of godot-cpp's design goals is to have the same API as internally in the engine (at least as much as possible), so, to add an is_class_static() method to godot-cpp, we'd need to first add it to the engine itself.
In your usage, i think ref->get_class() == MySubclass::get_class_static() can work great, no need to add new methods.
like:
class A : public Node.
class B : public A.
Ref<A> ref = get_my_class(); // return Ref<B>;
if (ref->get_class() == B::get_class_static() {
// ...
}
It is possible to do this with the existing methods, just as in GDScript. What I propose is to add an efficient StringName-based comparison that would complement an already existing function in godotcpp.