0 votes

I'm making an application where you can play piano.
Every key (black and white) has its own script that listens for input and handles presses, releases and drags accordingly. When a key has handled input, I use setinputas_handled() to stop propagating the input event.
The problem is that black keys are on top of white keys, and they should always be handled first, but as far as I can tell, there is no way to easily do so.
Is there something I can do in the editor, to move a node up in the _input processing order?

I know that I could write a separate class that keeps track of all buttons on the piano and does proper occlusion checking within that class before notifying a key press. But, I would prefer another solution, if there is one..

Godot version 3.4.2
in Engine by (26 points)

1 Answer

+1 vote
Best answer

I suspect you could possibly do this with the order of the nodes with the nodes lower in the branch firing first provided the input timing is same frame. It would definitely work on the ready function, not sure for the input, just put print(name) on a couple and you'll see the order of execution.

Otherwise, as you say, a class is a sensible option.

by (2,043 points)
selected by

I dragged the first-priority nodes down in the tree and that did the trick.
A shamefully error-prone fix, but good enough for me for now. :D

Quick dirty fixes are the pixie dust that holds all software together! Glad it saved you writing that pesky Key class, use those 20 mins we saved well! ;)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.