How to solve this communication problem?

woopdeedoowoopdeedoo Posts: 123Member
edited January 11 in GUI

In my map editor, I have a bunch of buttons in the UI that reside inside a MenuBar scene, and I have to connect those buttons' functionalities to the editor node. The problem is, to make the UI's complexity more manageable, I made some UI nodes packed scenes. The MenuBar is a packed scene and is inside another packed scene in the UI hierarchy, so signals can only be connected to that scene's root, and that blocks their communication with both the main UI node and the editor node itself.

I'm not sure how to tackle this. I can only think of two ways, and I'm not so happy about either of them.

  1. make the MenuBar and its parent packed scenes relay signals through each other up the chain to the main UI node, which can then relay to the editor node (which is down the hierarchy again, inside a viewport).
  2. have the editor node register itself in a global list of objects in an autoload (I have this in a core script), and then the buttons can do something like core.call_object("editor node", "undo").

Is there a better way to work around this?


  • vinpogovinpogo Posts: 63Member

    i would go for a third option. Add all of the signals you need to your Autoload script, and inside your UI Nodes simply emit the signals from your Autoload
    core.emit_signal('value_changed', new_value)

    Then in the scenes which need to react to those signals, you add this line of code to the _ready function
    core.connect('value_changed', self, 'some_method_to_call')

  • woopdeedoowoopdeedoo Posts: 123Member

    @vinpogo, that seems like a good idea. I'm going to be using it and see how I like it. It's better than my option 2 anyway. Thanks.

    Still open to other suggestions, though.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file