0 votes

Hello.
I have custom module which contains class:

class Player : public Spatial

And this contains:

private:
    Camera* _camera;
public:
    Camera* get_camera() const;
    void set_camera(Camera* p_camera);

(it just get/set the camera field)

The binding code:

ClassDB::bind_method(D_METHOD("get_camera"), &Player::get_camera);
ClassDB::bind_method(D_METHOD("set_camera", "camera"), &Player::set_camera);

When i try bind the set_camera method, the engine with module does not compile with error:

C2440
return: ���������� �८�ࠧ����� "const Variant" � "T" godot Q:\Games\GodotProjects\godot-master\core\method_bind.h 65

(debug/win32)

What i am missing?
Thank for help. (And sorry if my english not so good.)

P.S. And other question: what must be implemented for some engine class to can converted to Variant?

asked Mar 15 in Engine by MegaGeneral (22 points)
edited Mar 15 by MegaGeneral

1 Answer

+1 vote
Best answer

I had the same problem: https://github.com/godotengine/godot/issues/21160
Looks like it's just not possible at the moment. A workaround is to accept Object*, cast it with Object::cast_to and check if the result is not null.

answered Mar 15 by Zylann (26,045 points)
selected Mar 16 by MegaGeneral

Thank you, it is good idea while we wait for update.
I just do so:

void Player::set_camera(Object* p_camera) 
{ _camera = p_camera ? cast_to<Camera>(p_camera) : nullptr; }

And it working.

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.