How do I check if a specific object is overlapping an Area2D?

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

The issue I’m having with Area2D nodes is that they can detect when something moves into it, but I can’t find a way to detect if a specific object is already inside of it.

For instance, I’m working on a drag and drop system, with a draggable object and then an Area2D that you can drag the object into. It uses an on_area_entered signal.

I want to make it so that if you drag the object into the area and then release the mouse, only then will something happen. Instead, it just detects when the object enters while I’m dragging it in. I don’t know of any method to check whether the object is already in the area, or overlapping it.

:bust_in_silhouette: Reply From: Snail0259

You can use ‘groups’ (next to the inspector in the ‘node’ tab) you can create a new group called something like ‘body’, and your code could look something like this:

func _on_Area2D_body_entered(body):
    if body.is_in_group('body'):
        print('COLLISION!')

Hope this helps!