0 votes

How can I work with OOP in C++ module to be able to call by functions from GDScript?

For example: Room.get_human().get_name()

in Engine by (85 points)
edited by

Please clarify your question, OOP is quite a wide concept.
Do you want to call C++ functions from GDScript or call GDScript functions from C++? Or something else?

I want to call C++ functions from GDScript

1 Answer

0 votes
Best answer

In Godot, any class inheriting Object (or Node, Reference etc) have access to a reflection API allowing other languages to call methods on them.
You have to implement _bind_methods() and register your class in ClassDB.

This is covered in the official documentation here http://docs.godotengine.org/en/stable/reference/object_class.html#registering-an-object

And this is an example in Godot source code: https://github.com/godotengine/godot/blob/master/scene/2d/sprite.cpp#L295

by (27,829 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.