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()

asked Feb 11, 2017 in Engine by Kovalski (83 points)
edited Feb 11, 2017 by Calinou

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

answered Feb 12, 2017 by Zylann (21,017 points)
selected Feb 13, 2017 by Kovalski
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.