Trouble with get_overlapping_areas

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

So, I’ve been making some progress on my first project, but just hit a roadblock that I haven’t been able to figure out so far.

I have the _ready function of my main scene (“Level”) set up so that it’ll instance and add to the scene a certain number of Area2D scenes that belong to the group “pieces”. Said “pieces” each have 3 child nodes that are also Area2Ds - albeit on different layers - and belong to the group “sides”. As far as I’ve been able to test it, all the grouping stuff seems to be working just fine.

The “pieces” are added to the scene in the correct positions, and some of the “sides” overlap as intended. However, calling get_overlapping_sides() on each “side” returns an empty list. This only happens during this initial setup, and the function seems to work just fine in other situations when it’s called during actual gameplay.

Does this have something to do with the specifics of how scenes enter the tree? Should I use call_deferred() or something? I’m a beginner and still haven’t managed to wrap my head around how that works.

:bust_in_silhouette: Reply From: Ertain

The function get_overlapping_areas() is related to the physics properties of the engine. Specifically, it utilizes a CollisionObject2D to calculate how physics and collisions are handled. Since the physics server can use a bunch of threads and processes, it is recommended to use the _physics_process() callback for your collision needs.