Godot Version
4.5
Question
how do I connect my CheckBox named “shading” in the scene “MainMenu” to my DirectionalLight2D named “DirectionalLight2D” in the scene “root”
4.5
how do I connect my CheckBox named “shading” in the scene “MainMenu” to my DirectionalLight2D named “DirectionalLight2D” in the scene “root”
The easiest way is usually through a group: Create a global group that contains only the DirectionalLight2D, then you can access it via get_tree().get_first_node_in_group().
Are you working with game settings (e.g., the “shading” checkbox is a user setting they can turn on and off)? To transfer the information between the two scenes, you might make a settings file using ConfigFile or looking at a tutorial for using resources to save settings and game info.
There’s several ways you can solve this. One way is with groups, like the other commenter mentioned.
Another is through signals. It’s hard to give specifics without seeing your scene tree, but the two nodes should have a common parent somewhere up the chain. So send a signal to that common parent, or call the parent in some way, so that the parent can then send a signal that the directionallight can connect with. Doing this means neither the light nor the checkbox have to know about each other, and you can potentially connect other nodes to the same signal.
Let the checkbox send signal to MainMenu root. There you can implement a higher level signal that forwards it. That way you’ll be able to manually connect to instances in the editor.