+3 votes

I'm working on a project in 2.1.4, which is mostly just GUI interfaces and switching between scenes at the moment. Scene tree looks like this:

  • main (Node)
    -- instanced scene 1 (Control)
    -- instanced scene 2 (Control)

... and so on (instanced in the editor rather than code btw). Now if I want a button press in scene 1 to activate a function in scene 2, what is the best way to go?

I've tried signals, but I've spent three evenings trying various approaches to this (signal manager singleton, get_tree().get_root().get_node()), but the latter always seems to return a null instance, and the former is even more complicated. Of course, I've tried to link by creating the signal and linking through the editor signal window too, but that doesn't produce anything!

Has anyone got any advice to achieve something like this? Any help would be much appreciated.

EDIT: The problem was that I was using get_tree().change_scene(), which was reinstancing a scene on its own, when I wanted it to just switch between them. I've since swapped to hiding and showing the various scenes, and signals are now working using the ("../scene1") etc., which I know is bad practice, but i'll come back and tidy up once i've finished a prototype.

in Engine by (30 points)
edited by

Are you looking to communicate between scenes? I did a quick search and found this.

Yeah, I've previously made that game and rewatched when I hit this problem, but actually it looks like I need to re-look at how i'm switching between scenes and make sure i'm not de-instancing scenes as I go (see below response ...)

Thanks for the response!

1 Answer

0 votes

First, be sure these siblings are not both part of the same scene, if they have independent behaviour, is most likely they are unique, but if have a constant communication between siblings, both may be part of the same scene (meaning that you are exceeding the atomization).

Then, signals, yes! but when?
Your manager get nulls probably because is trying to make connections of things that are not yet in the tree, there is where your main scene node need to work, when the current scene root (not the tree root) is ready, means that all it's children are ready, and that is the moment where you can "wake up" your signal manager to get and connect nodes.

Also, try to group these nodes so they are easier to get from anywhere on the tree with get_nodes_in_group (and the current scene root does not need to know where are they).

by (7,866 points)

Yup, i'm an idiot - I worked it out just before I went to bed last night - the scenes are all instanced but I switch between the different instanced scenes with get_tree().change_scene() - not realising that it was instancing a new scene that didn't have the siblings.

Now I know the problem i'll fix it, retry the methods I was using and post what worked for me. The group thing is interesting though and I'll look into that too.

Thanks for the help.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.