How do we only check collision for area 2D when called by a function?

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

Hey, I am developing a 2D city builder style game inside Godot. Currently, I have Over 40 area2Ds every game, due to people being able to spawn in a building with four of them each. However, the Buildings are constantly checking for other buildings they are colliding with. I am afraid that this will cause large lag problems in the future. Is there any way I can check for area2D collision from a function call instead of every frame?

For example, can I use a function that checks for a collision once? Instead of Area2D checking every frame.

Currently, I am using the Area2D_entered(area): function

Thanks for the help :slight_smile:

:bust_in_silhouette: Reply From: Wakatta

In my tests I’ve used Areas_entered(area): for over 300 agents in 3D without any noticeable fps drops.
You can however use Area2D’s get_overlapping_areas() function which returns an array of areas within the bounds of the Area2D its called from

Oh ok, Thank you. Sorry for the late response. I didn’t know get_overlapping_areas() was a thing. And it’s great to know that there shouldn’t be an fps drop. This is super helpful. Thank you :slight_smile:

OreganoDev | 2021-02-04 19:26