When I had problems scanning an area for viable attack targets (allies rescan area when an enemy dies) in the process or physics_process functions, I was able to overcome it by using timers, and rescan when the timer reaches timeout(), and resets the timer at the same time.
var s_timer = get_node("Scan_Timer")
func _on_Scan_Timer_timeout():
rescan_for_target()
s_timer.start()
func rescan_for_target():
var scan_area = $Detect_Area
var scan_bodies = scan_area.get_overlapping_bodies()
for scan_body in scan_bodies:
if scan_body == self:
continue
if scan_body.has_method("process_UI"): #_hit"):
print ("viable body")
calculate_path()
And then I adjusted the time value for the timer to about 0.03 (about 30 times a second).