One script for mutiple nodes

Godot Version

4.0

Question

I have a .gd script that I want to apply to multiple buttons, and the script contains the _on_mouse_enter() function, but if I apply the script to multiple buttons it does not let me connect the mouse_enter event to the script if mutiple buttons have the script at the same time. How can I make it so that the scripts are independent without just copying the original script over and over?

You should be able to connect a signal to the script in the editor independently of if it’s being added to one or multiple nodes.

Either way, you can connect the signal in code so you don’t need to manually connect it in the editor Using signals — Godot Engine (stable) documentation in English

1 Like