I'm using a signal bus, but isn't work fine

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ClooouD

Hello guys

So… I created a singleton code that will carry all signals that i will be using in project. Then if a node needs to connect with other node, it will need to call the Signal_bus as the example below:

->Signal_bus.gd:

signal start_conversation

->Text_manager.gd (code_A):

Signal_bus.connect("start_conversation", self, "initiate_conversatrion")

->Scene_1.gd (code_B):

Signal_bus.emit_signal("start_conversation")

If the example wasn’t clear enough, here is the tutorial that i’m watching.
The following image is how i’m building my node’s hierarchy: My node’s hierarchy

The emission of signal coming from code_A to code_B is working and it activates code_B’s functions properly.
But i need that code_B emits a signal to activate some print text funtions carried by code_A and its not working.

Someone has any clue about what is happening?

:bust_in_silhouette: Reply From: jtarallo

The emission of signal coming from codeA to codeB is working and it activates codeB’s functions properly.

I think you got a bit confused there mate. The code example you provided emits a signal from codeB to codeA. If you need that the direction of the emission goes the other way around, you need to connect the signal in codeB instead.

I am not getting the use you’re getting out of this system though. Are you sure you need this kind of complexity for what you want to do and can’t just depend on normal callbacks to provide you with the functionallity you need?

Signals are useful but I’d try not tu abuse them or your code can get real messy real fast.

I think you got a bit confused there mate. The code example you provided emits a signal from codeB to codeA. If you need that the direction of the emission goes the other way around, you need to connect the signal in codeB instead.

I need the code to work as in the example i gave: Scene1(B) must emit the signal connected to a function in Text_manager(A).

I made the connection from A to B just for test. And it worked in this direction, but not the oposite.


I am not getting the use you’re getting out of this system though. Are you sure you need this kind of complexity for what you want to do and can’t just depend on normal callbacks to provide you with the functionallity you need?

I’m using this system because the scenes will be replaced by code. When i tried to do it in a “regular way”, using get_tree().get_node() for example, i got lost about how to use the connect with a variant path.

ClooouD | 2020-06-08 18:43

I think I know where your issue comes from. Remember the code in your scripts execute in the order the nodes are added in the scene, from upwards to bottom. So you’d need the connect code to execute before the signal is emitted when your scene is added. So, i’d move the Text_manager node to before the ViewportContainer node.

I strongly recommend that you handle your scene hierarchy and instancing differently because this will become tricky when your scene grows and if you need Z positioning which is not the intended one for this script loading order to work.

jtarallo | 2020-06-08 19:56

I strongly recommend that you handle your scene hierarchy and instancing differently because this will become tricky when your scene grows and if you need Z positioning which is not the intended one for this script loading order to work.

I will be careful about it.


Following your recommendation i changed my hierarchy and it worked. Thank you, bro.

ClooouD | 2020-06-09 17:42

No problem, glad to be of help. Good luck!

jtarallo | 2020-06-09 17:44