#How to make a script unique to multiple instances of a node?
1 messages · Page 1 of 1 (latest)
this has nothing to do with the script not being unique; when you can a function it will only run in the object (ie. the specific node) that you called it on, regardless of the script being unique or shared
how are you calling that function?
I’m calling one of the functions through connecting a signal, and the rest of the functions are in _ready and _input
_ready() and _input() runs on all nodes, _ready() on each node when it enters the scene tree for the first time (basically when it "spawns"), and _input() runs on all nodes every time an input event is received by the engine (note: all nodes with that function always receive every input, it's not like _gui_input which filters clicks inside of the node)
signal connections are also from a specific object to another specific object
a signal of one object can be connected to multiple target objects, but these connections still need to be made individually somehow
if you expected the texture rects to handle clicks inside of them you probably want to change _input to _gui_input
Alright. How do I make the _ready() function work only for that specific node?
Also is connecting the signal in the script okay? Will the signal only work for that one node?
Should I use _enter_tree()?
If you want something to run in only one of those nodes, you're going to need either an outside node that selects one of them and then calls a function on just that one, or some value that differs between them, like for example an id that you set with an exported variable and you only run a function if the id is equal to, say, 0
Using _ready() or _enter_tree() or_input() with no further checks will make the code run on every node
It would help to know exactly what the functions in question are
The approach will depend on that a bit
_ready() already runs on each specific node
and yes connecting signals through code is fine