+2 votes

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 onareaentered 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.

Godot version v3.3 Stable
in Engine by (21 points)

1 Answer

0 votes

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'):

Hope this helps!

by (246 points)
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.