0 votes

I want my Area2D node to detect if it is overlapping with any other Area2D (across scenes) in every frame. Here is my code -

extends Area2D

var invalid = false

func _process(delta: float) -> void:
    if overlaps_area(**problem**):
        invalid = true

What do I put inside overlaps_area()?

What is the expected argument type?

The documentation Area2D area doesn't work. What else do I have to do?

Thank you and Sorry.

Godot version 3.3.2
in Engine by (25 points)

1 Answer

0 votes
Best answer

overlaps_area() checks if the area is overlapping a specific other area. You pass a reference to the second Area2D as the argument.

If you want to check if it's overlapping any other area, you want to use get_overlapping areas() instead, which returns an array of overlaps.

by (20,485 points)
selected by

Thanks for the answer!
I used -

extends Area2D

var invalid = false

func _process(delta: float) -> void:
    for area in get_overlapping_areas():
        if "name" in area.name || "second_name" in area.name:
            invalid = true

and it worked perfectly!

By the way your tutorials are very helpful :)

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.