#Signals: attach in code, or node dock?

6 messages · Page 1 of 1 (latest)

tight wind
#

Hi, I'm reading the documentation about connecting to signals:
https://docs.godotengine.org/en/stable/getting_started/step_by_step/signals.html#connecting-a-signal-in-the-editor
I understand how to do it in the node dock and in code. I understand that there are various situations wherein you must connect in code, and cannot use the node dock to achieve the desired behavior. Outside of those situations, is there any reason to prefer connecting in the node dock instead of code? Would it be a bad idea to just make all connections in code only, and never connect signals in the node dock?

grave cloak
#

Well the node dock allows allows developers to connect signals without modifying the script. I guess the benefit would be user friendliness, but it can also be very redundant if you need to connect everything. It depends on your project and use case.

verbal needle
#

It's a matter of preference, personally I do them all in-code, generally in the _ready() function. Advantage is that you can clearly see all the connections you've done.

surreal forge
#

One case: You're working with a level designer and trying to provide handy tools for hooking up behaviour between nodes in a non-static way. This can be especially handy for rapid prototyping, in order to try things out with prototype levels before you lock things down into static code.

Example: You create a very generic collectible, and the designer can decide what behaviours should be triggered on the "collect" signal. One might call give_coins with some parameter while another calls open_door on a specific door in the level. This saves you from needing to make different types of collectibles for each thing you want triggered, or some uber-collectible that has all the behaviours inside it, and even allows the designer to use it to trigger things you didn't specifically expect.

#

As for whether it's a bad idea to make all of the connections in code, no, not really.

#

You'll likely find that even if you aren't hooking up the signal itself in code, you probably need to set up a node reference to know what to connect to, though. This is fine, and can be more tightly controlled so could even be good in some cases. My point is just that you'll still be setting up something in the editor in those cases.