get_overlapping_areas() not working when changing collision size

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

So I’m trying to make a way to select multiple objects in my project. I want it basically like Windows, where you can click and drag to create a box that you can use to select items that are in that box. I got it to create the selection box using a Polygon2D, and making it show up correctly, following the mouse, etc. So then I added an Area2D and a CollisionPolygon2D to that Area2D. I found out that I need to use get_overlapping_areas() on the area. When I do that though, it returns an empty array, unless I start the selection in an area. I had also tried using the area_entered signal, but it doesn’t work either. I made the box stationary, and moved areas into it, and then it worked correctly. I’ve also verified the collision shape is correct by enabling show collision shapes.

To update the box, I’m just updating the PoolVector2Array of points. I’m wondering if maybe changing the shape of the collision object is preventing it from detecting if an area is inside. I was hoping get_overlapping_areas() would actually do the math to check if an area is inside another, but it appears like it just retrieves the list that is updated everytime an area enters.

Does anyone have any suggestions or clarifications if I’m not understanding correctly?

TL;DR I want to get all areas inside another while I’m changing it’s shape, and it’s not working.

The list of overlapping_areas is only updated each physics frame. See here:
Area2D — Godot Engine (stable) documentation in English

Returns a list of intersecting PhysicsBody2Ds. For performance reasons
(collisions are all processed at the same time) this list is modified
once during the physics step, not immediately after objects are moved.
Consider using signals instead.

Ok, the docs don’t make clear if the check is also performed (each physics frame) when just the points of the collision shape are updated but the object does not move. You’d have to try it out. (Doesn’t hurt to enable monitoring on all colliding areas for that test.)

If you’re working with rectangular areas then maybe the using the Rect2 class with the methods encloses() or intercepts() might be helpful? (Similar to AABB in 3D).

wombatstampede | 2019-12-04 09:17

That moment when you find a post that you think is going to help, because the problem is described exactly the same as yours…

And then you see this was your own earlier post.

TheSecurityDev | 2020-06-22 17:45

:bust_in_silhouette: Reply From: TheSecurityDev

It seems like it only updates if the Areas change position. So I simply tried setting the position to (0, 0) (unchanged) everytime I want to get_overlapping_areas(), and that seems to force it to update, because now it works!!!