+1 vote

I have custom module which contains class:

class Player : public Spatial

And this contains:

    Camera* _camera;
    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:

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


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?

in Engine by (24 points)
edited by

1 Answer

+2 votes
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.

by (27,896 points)
selected by

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.
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.