In my game I am creating multiple instances of a ball and put them into the main game.
I want to be able to know when a instance is touching the players hitbox and when this happens for the ball to change its animation.
I have been trying to use signals but I have not been able to link it up to the ball since it does not start in the main scene.
Is there a way to use signals to achieve my goal or am I looking at this the wrong way?
I think there is a way but I wouldn’t rly do it like that.
You can connect signals in code, to avoid “unable to link up in editor because object doesn’t exist yet” problem you have.
But personally I don’t think it’s that good of an idea for your specific problem. You can’t send signal to a specific object. You simply emit the signal and all potencial listeners will be notified - So I assume player is the emitter and all of the balls would be listening. You can work around it. For example you can send colliding body as argument in the signal, then all balls processing the signal would check if colliding body is theirs and only change animation if it is.
Now let me present you what I think is simpler alternative.
Once player detects that some ball is touching, it simply calls a function on this ball. You just define your behavior on the ball and then just have it invoked by outside object - the player. I think this is the most simple and most fitting for what you’re trying to do here.
Signals are very good when emitter doesn’t care who will recieve the signal - In your case you very much care about specific ball being only one to respond to it.