0 votes

I have a character with an Area2D which detects when something I can interact with enter my reach.
But in order to know if it's indeed something i am able to interact with, I would normally test if the object implement a certain interface.
How should i handle it in GDScript ?
Use groups or has_method() or collision masks or is there another solution ?

Thx for the help.

in Engine by (28 points)
edited by

1 Answer

+2 votes
Best answer

Oh man there are so many options but groups are probably the most reliable
also no harm in having multiple for unique cases

There are Class comparisons if character is StaticBody
The are groups if character in get_tree().get_groups("agents")
There are property/member lookup if "this_var" in character
There are enum use cases if character.type == my_enum.my_value
There are custom nodes if character is my_custom_class

by (4,638 points)
selected by

Thanks, it helped a lot !

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.