0 votes

OK, I'm going to confess, I'm still new to C++ but learning as I go, anyway. I'm trying to implement a simple 2d collision check using rectangles (my own type "Rectangle2d") that doesn't require the physics engine and I want to check for overlaps against another rectangles. Sounds simple but I hit a problem when trying to bind the method and compile. I've got modules working before so this is a specific problem.

so far I have the header, very simple ...

bool overlaps(const Rectangle2d& p_other) const;

I have the implementation in the cpp file (defaults true for now)

bool Rectangle2d::overlaps(const Rectangle2d& p_other) const {
return true;}

with the method bind


But when I go to compile, I get the following error

'return': cannot convert from 'const Variant' to 'Rectangle2d'

Am I not a allowed to pass a reference to the same type, or am I missing something more fundamental? I have been trying to follow other examples in the code base where a Vector3 might be passed in, I would appreciate any help or even a link to an example where something like this (self type reference passing) has been done before that I could follow along with.


in Engine by (31 points)
edited by

Not an answer for the binding issue, but you know that Shape2D already have that simple overlap thing?

1 Answer

0 votes
Best answer

It looks like when you expect a type that is not derived from Object, Godot tries to convert it to Variant.
In fact, all types that don't inherit Object are listed in Variant https://github.com/godotengine/godot/blob/master/core/variant.h

I doubt you want to inherit Object though, because you want your Rectangle2d to be a value type, not a reference type.

I don't know what can be done to add a value type without adding it to Variant, but there is already a Rect2 with intersection methods so your class would just be redundant.

by (29,090 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 Frequently asked questions and 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 [email protected] with your username.