Possible to tell if two collision shapes are overlapping (not entered or exited)?

Godot Version

v4.1.3stable

Question

Ok so here’s what I’m trying to do: I would like to direct my playable area2d or characterbody2d into a target area2d, and then while overlapping with that collision shape, have the option to call a function using an input.

As I have it now, I have a “on_body_entered_” signal from the target area2d into the playable character’s code. But the problem is, that since the ‘body_entered’ event has already happened, I don’t have the ability to call any functions while the two collision shapes are overlapping.

My initial idea to make this work is to have a true/false var that is triggered by body_entered, which while true would allow for the functions to be called, then the var would become false on body_exited, thus inhibiting the option to call said function. But that seems like more work than it should be.

I’ve read the docs and I’m very familiar with the various built-in signals of the area2d node. Is there something I’m missing; some way to check if two collision shapes are actively overlapping after one has entered the other?

Thanks

If you are using an Area2d you could use

$Area2D.get_overlapping_areas()

Which will return a list what areas are overlappinng with the Area2d. It can also tell you what bodies are overlapping with it using

$Area2D.get_overlapping_bodies()

Edit:

You should be able to use this to detect both bodies and areas

	var overlap_query := PhysicsShapeQueryParameters2D.new()
	
	overlap_query.collide_with_areas = true
	overlap_query.transform = global_transform
	overlap_query.shape = $CollisionShape2D.shape
	
	var overlaps = get_world_2d().direct_space_state.intersect_shape(overlap_query)
	
	for overlap in overlaps:
		print(result.collider.name)