0 votes

I have an Area2D class in GDNative which connects to the signal "body_entered" when a bullet enters it.

I really, really don't know why, but this is what I have in the Area2D script, inside the function which is supposed to react to the signal:

Bullet* bullet = (Bullet*) body; //this makes the game crash and returns wrong property values when accessing bullet functions

instead

Bullet* bullet = Object::cast_to< Bullet>(body); //this makes everything work fine, both property access and function usage, without crash

Could someone explain me why?
I wonder which syntax to use depending on the situation.

Godot version 3.2.3
in Engine by (26 points)

Please log in or register to answer this question.

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.