Use groups as Interface ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Giiltham

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

:bust_in_silhouette: Reply From: Wakatta

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

Thanks, it helped a lot !

Giiltham | 2021-03-21 19:28