Detecting overlapping areas immediately after moving object preview

Godot Version

4.3

Question

Hi!

I am working on a placement preview for placeable objects. My object hovers in front of my player character and is always on top of my mouse position. I can then place it with a left click, which clones the object. I update the position of my object during the _process function call, so I have the most up-to-date camera transform.

In this image you can see a placed object in blue on the left and my placement preview in green on the right.

Placed objects should not overlap. For this I have added an Area3D with a CollisionShape3D to all my placeable objects. This Area3D determines the areas that cannot overlap between two placed objects. I would like to include this check during the placement preview, so my player knows whether the object would overlap if placed right then and there. At the moment I first update the position such that the placement preview is aligned with the mouse cursor position and then check if its Area3D overlaps with any other Area3D. However, the get_overlapping_areas() function only updates right before the physics tick, according to documentation. This means that when I update the position during the _process function call, I don’t have up-to-date overlapping areas. In practice, this means that the placement preview flickers for 1-2 frames, thinking the object is placeable until the overlapping areas are updated. This is especially visible in my case, since I quantize the placement to a grid and get z-fighting during this short period.

Is there a way to force recomputation of overlapping areas or is there a better way to do what I would like to do?

Thanks a lot for any help :slight_smile: