0 votes

Hello,

is it possible to play a specific sample everytime any Button gets pressed without changing every single button individually?

Something like a global setting or theme setting.

Or do i have to implement my own Button class derived from Button which then will call the play function?

in Engine by (289 points)

I don't think it's possible but I've never needed it so IDK

1 Answer

+1 vote
Best answer

I dont't think themes have this, but you have several ways:

1) You can have a script iterate over all nodes of the scene, find all those that inherit Button and add a connection to the same function on your script. So when you press any of the buttons it will trigger the function.

2) Have your own button script or scene that handles sound the way you want (I would do that personally because it's more flexible).

by (27,170 points)
selected by

can you explain 2) further?

in my case i have like 50+ buttons and i want them all to play the same click sound. thats why i want a central solution.

or is " your own button script" meant as an inherited version of the class Button?

Yes, you would make a script inheriting Button to do whatever you want with it.
If you have 50 Buttons you can have a script running through them to connect a signal or add a script like in 1), or make a new scene for that kind of button (with a script in it) and instance the scene 50 times. This way you'll be able to change all these buttons by simply changing their scene.
Also, as a general tip, if you find yourself copying and pasting something many times, there must be a way to factor it so you'll be able to change instances more easily :)

> if you find yourself copying and pasting something many times, there must be a way to factor it so

agree, thats what i meant with "central solution"

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 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.

Categories