Node connection between scenes

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

Hey!

I would like to create a 2D Path advanture game with many scenes call them Rooms. So, I would like to make connection between rooms’ node.As far as I know, I can set subscenes to a parent scene and in that scene I could make these connections, but I’d like to edit these rooms, avoid to overwrite parent/root scene by editing them separately.
e.g. There is a switch in RoomA wich is connected to a door in RoomB.
Is there any solution to achieve this?

:bust_in_silhouette: Reply From: Jatz

In the scene tree panel, next to the instanced scene. Click on the dropdown movie icon. A menu should come up. Check editable children. now you can edit it to your heart’s delight.

That is clear, but not completly I want. When I made changes on the root scene it apply changes to it not to the edited subscene. I would like to avoid to overwrite the root scene as many times as I edit its subscenes.

Gergő Tamási | 2017-01-18 13:42

I think n you are going to have to explain you scene structure to me

Jatz | 2017-01-18 13:55

then I’m trying to describe the structure:
Our game consists of chapters: A B C
In each chapter we have locations: A1 A2 A3
Each location has 2D interactable contetn and static as well. Between this locations there are some logical connections. I mentioned a example above. Because of these kind of connection, we should use signals or something like those. In addition, we’d like to edit these location separately, because more than one designer would work on them. We want to avoid overwrites the chapter container( here parent scene).
Question is: is this parent scene necessary? Or could we achive same result with another approach?

Gergő Tamási | 2017-01-18 14:12

If I’m understanding you correctely:

  • You can try to use a Singleton
  • You can put a node below get_tree() store your variables in that. then when the next scene loads import it from there.
  • You could load one scene, put your variables from the old one into the new one, then remove the old scene.

This is what I meant you could do

  • chapter_A.tscn
    • Node
      • A1 instance (editable children on)
        • switch
      • A2 instance (editable children on)
        • door
      • A3 instance
  • scene_A1.tscn
    • switch
  • scene_A2.tscn
    • door

in the chapter_A.tscn scene
connect door to switch
alternatively:
use a NodePath you are sure will be true

etc…

Jatz | 2017-01-18 14:46

So, in case of first solution, I cannot avoid chapter_A.tscn being accidently conflicted.

What if I write a tool which stores all NodePaths and use them as references for logic connection?

Gergő Tamási | 2017-01-18 14:57

You could also do the following, tell people to not save chapter_A.tscn or make it read-only or something.

inside chapter_A scene:

  • link the door to the switch
  • right click on scene_A1 node
  • click save branch as scene
  • save it as scene_A1

This should insure no conflicts (I think)

Jatz | 2017-01-18 15:10

I cannot save the instanced scene. :expressionless:

Gergő Tamási | 2017-01-18 15:37

Under the movie icon, discard scene instance
Then right click, save branch as scene :expressionless:

it’s a hackish solution

And it’s reliant on the rooms staying in memory, (not being free’d)

Jatz | 2017-01-18 15:52

:bust_in_silhouette: Reply From: avencherus

Generally this is achieved with globals, or at least variables higher on the stack than the scenes.

Three methods you could explore are:

  1. Creating singletons using autoload, explained in detail here: http://docs.godotengine.org/en/stable/tutorials/step_by_step/singletons_autoload.html

  2. Going off the singleton concept, the scenes themselves go in and out of memory, but the scene tree does not. Autoload appends things to the root of the scene tree. You could do this manually, and these things will move from scene to scene.

  3. Directly set and unset things in the Globals singelton.

Globals.set("room_2_switch_on", true)
Globals.get("room_2_switch_on")

Globals.room_2_switch_on = true
if(Globals.room_2_switch_on)

The get() is useful if you want to test to see if the Global exists before using it. And there is also a clear() method for removing them.

So there isn’t any way to get all node(nodepath) in the Scenetree?

Gergő Tamási | 2017-01-20 13:52

I’m not sure what you mean.

avencherus | 2017-01-20 17:47