What is overlaps_area() argument for all Area2D nodes?

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

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.

:bust_in_silhouette: Reply From: kidscancode

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.

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 :slight_smile:

scorder | 2021-09-04 11:44