How to check inside of the area if its empty or not?

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

I have instanced objects that erase themself with timer.

when they are insade a area_node(placed on enemies) code will do something, but while stil insade the area_node, instanced objects erase themselfs.

So area’s inside get empty, when its get empty, i wanna do something else, but area body_entered function not update itself like process function, so i cant get the return value, or dont know how?


func _body_entered(body):
	body = instance_piece
	if body == instance_piece:
		follow_triger = 1
	if area is empty: ### ---> need to do this.
		follow_triger = 0

func _physics_process(delta):

	if follow_triger == 1:
		print ("do someting if instanced body entered")
	if follow_triger == 0:
		print ("stop what you are doing if area is empty")

its allways return the follow_triger 1 value.

:bust_in_silhouette: Reply From: Magso

get_overlapping_bodies() returns all physics nodes in the area.

To replicate unity’s OnTriggerStay function

if get_overlapping_bodies().size() > 0:
    for body in get_overlapping_bodies():
        #Do stuff with all bodies in area

thanks, it works. well, for objects i was using spatials so insteed get_overlapping_bodies, i did use get_overlapping_areas after i did add the area nodes to spatials.

if follow_triger == 1:
if follow_triger == 0:
	print ("object not found")

if area_node.get_overlapping_areas().size() > 1:
		print ("more then 1")
		follow_triger = 1
	follow_triger = 0

morningkingdom | 2020-12-12 19:18