Using _has_overlapping_bodies() for a signal (unresolved for now)

Hi, I’m sorry I couldn’t develop more the title because of my lack of english, i’m gonna explain here what is my problem.

Actually i’m trying to hold a signal that is :

func _on_area2D_entered(Note):
    var currentstate = Note.get_parent()

in this piece of code, i wanted to add an input detection when an object has entered the area like so :

if Input.is_action_just_pressed('Space Keybind"):

however when I use this pattern in my func _on_area2D_entered() it only captures at perfect timing so i would like to get a hold of the signal that has a long duration, i’ve been looking on godot docs and saw that there was a boolean that could’ve helped me for a while true: loop, this one is

bool _has_overlapping_bodies() (found in area2D)

However i don’t really know how to use it that’s why i’m asking some help here ^^" I hope i don’t bother y’all and i’ll be thankful for any help from you all. Also i’m doing this post for people who don’t know how to use it since it seems like i didn’t find a post talking about this boolean.

Have a nice day !


Sorry to ask, but I want to make sure I understand what you want. Do you want to make a script where, if the node is inside another area2D and pressed a button, the script will run?

Hi. You shouldn’t use a while loop, since that will lock the game up and prevent it from advancing. You should instead listen for inputs in the _input or _unhandled_input function. For example:

func _unhandled_input(event):
    if event.is_action_pressed("Space Keybind") and has_overlapping_bodies():

Hi, thanks for your proposition however, i’m planning currently on making a rythm game where instances spawn and go towards the area2D mentioned earlier. I want that the little notes that’ll pop up gets detected during their way through the area 2d and during that time i want the player to be able to push space to queue free the instance that is being detected in the function _on_area2D_entered()

also, i cant put unhandled input inside my function do i have to put it outside or something ???

(i’m sorry for wasting your time like that )

There are a few ways you could do this, but since you’re making a rhythm game, here’s what I would do.

Create a variable called current_note

Whenever a note enters the area, use the _on_area_entered(note) method to set current_node to the node that’s entered the area.

Use _on_area_leave to set current_note to null

Use the Input.is_actioj_just_pressed to check when the user presses the correct input AND THEN check that currebt_note has a value.

Hi, thanks for your response but do you know if there is actually away to make the signal emitted constant so during the way of my note through the area i can detect it during its way and so while its getting detected in that specific area you can push “space_key” and so act on it with a queue_free ?

There is not. Signals are designed to allow other nodes to react to events, they can not constantly emit. The closest to that you can get is emitting a signal every frame, which you could do by using the process function and having it emit a signal if a condition is met.

unhandled input is a function, you can’t put functions inside other functions.

I see, anyways thanks for answering me, have a nice day man.