Skip to content

Conversation

limbonaut
Copy link

@limbonaut limbonaut commented Jan 10, 2024

Link to proposal: godotengine/godot-proposals#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()) {
  // ...
}

@limbonaut limbonaut requested a review from a team as a code owner January 10, 2024 12:14
@dsnopek
Copy link
Collaborator

dsnopek commented Jan 10, 2024

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.

@dsnopek dsnopek added the enhancement This is an enhancement on the current functionality label Jan 10, 2024
@dsnopek dsnopek added this to the 4.x milestone Jan 10, 2024
@pupil1337
Copy link
Contributor

pupil1337 commented Apr 25, 2024

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() {
    // ...
}

@limbonaut
Copy link
Author

limbonaut commented Apr 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This is an enhancement on the current functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants