• Godot Help
  • How to connect two other objects via signals

Maybe I'm misunderstanding something, but judging from the method signature of Object.connect, only the object that "owns" a signal can subscribe other objects to it, since the owner cannot be specified:
connect (String signal, Object target, String method, Array binds=[ ], int flags=0)

Is there perhaps another way I can connect two objects without them knowing about each other? Specifically, I want my editor plugin to subscribe a gizmo to a signal in my editor state object, so it redraws itself when the state changes -- without having the objects tightly coupled.

  • DaveTheCoder replied to this.
  • lincore since the owner cannot be specified

    By "owner" I guess you mean the node that emits the signal.

    If NodeA emits a signal and NodeB handles it, you can prevent the two nodes from having to know about each other by doing the connection in a common ancestor of NodeA and NodeB.
    NodeA.connect("signal_name", NodeB, "signal_handler")

    It could be any node, not necessarily a common ancestor, but it's reasonable for a node to have information about its descendants.

    lincore since the owner cannot be specified

    By "owner" I guess you mean the node that emits the signal.

    If NodeA emits a signal and NodeB handles it, you can prevent the two nodes from having to know about each other by doing the connection in a common ancestor of NodeA and NodeB.
    NodeA.connect("signal_name", NodeB, "signal_handler")

    It could be any node, not necessarily a common ancestor, but it's reasonable for a node to have information about its descendants.

    Well they are connected, so there has to be a link somewhere. They kind of have to be coupled or there is no way to communicate. It's sort of like trying to send someone an email without their email address. How would that work?

    My interpretation is that both nodes need to know about the signal, but not about each other. One node emits the signal and the other node handles it. But the emitting node doesn't need to know what node will handle the signal, and the handling node doesn't need to know what node emitted it.