Where do non-code based connections get stored?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By user41420082
:warning: Old Version Published before Godot 3 was released.

I was checking out the tutorial and one thing I noticed, I can use

get_node("Button").connect("pressed", self, "_on_button_pressed")

to connect a button’s press to a function right? That’s how to do it programmatically. Now I add another button but this time, use the GUI approach of clicking the plug icon to link it to the function. The function works without problems however, I don’t see

get_node("Button 2").connect("pressed", self, "_on_button_2_pressed")

anywhere on the script file. So where is this being stored? Are the GUI and the code based connections separate? Why is that? I was expecting it to add the same connect code beneath the one i manually typed.

And vice versa, the code I manually typed doesn’t seem to register on the button when I check it out via the plug icon approach.

:bust_in_silhouette: Reply From: GlaDOSik

Good question. We can easily test it. I have a scene with node directional light called light. I will connect signal visibility_changedto function _on_light_visibility_changed inside script testing_scene.gd. Let’s save the scene to .tscn file, so we can see what’s inside. And here we go. There’s our signal:

[connection signal="visibility_changed" from="light" to="." method="_on_light_visibility_changed"]

The dot next to “to=” is the path to spatial node (it’s a parent of light) with my script. Thus signal connections made in editor are saved inside your scene file. Why? Maybe, it would be hard to synchronize the content of the script with editor GUI? Don’t know for sure.

Thanks for the answer! Hopefully someone from the Godot team chimes in with word on the why and if it’s being addressed in the future. I somehow had the hunch it was getting stored in the scene itself. I just didnt want to change to .TSCN because I read that .SCN is better performance wise on the forums I think.

user41420082 | 2016-07-04 22:09

It’s actually easy to see why: the code and the scene are separate things.

The GUI cannot edit the code, it can not even tell in which script it’ll be added (since where it’s connected and the function to execute don’t need to be in the same place). You can even connect things in a scene without scripts (e.g. a button that calls hide() on a popup when pressed, you don’t need script for that).

If you do it by code, there’s no way for the GUI to know. In code you can even connect dynamically, so the editor would have to run the code to see what’s the connection.

As a note, while it’s true that .scn has better performance, .tscn files are converted to .scn on export. And this is for loading only, since they’re the same in memory after loaded.

vnen | 2016-07-06 18:00

:bust_in_silhouette: Reply From: Shin-NiL

I think it’s saved on the scene file. Using the tscn format, it’s easier to note something like this:

[connection signal="pressed" from="Button 2" to="." method="_on_Button_2_pressed"]

I do prefer the programmtically way though, it’s clearer to me :stuck_out_tongue: