• Godot HelpGUI
  • Yet Another Connect-the-Signal question, about the tutorial

Working through the Signals Tutorial, and it's not clear what's really happening.

It looks like there is a "top-level" Scene, which has a child Sprite-Scene - and the tutorial is adding a Button to the top-level Scene, then connecting it to a script, that is attached to a Sprite, that is inside the child Sprite-Scene. IOW, not modifying the Sprite-Scene itself. But all I get is "cannot connect signal, target method not found."

I could add a button directly into the Sprite-scene and connect it, no problem. And it looks like if I attached a script to the 2D Node at the top of the Sprite-scene, that would also give the top-level Button, something to connect to.

But if I understand this right, the top-level Button is connecting to existing Sprite's script (which does have an "_on_Button_pressed()" func. So it's treating the Sprite-scene as a single Component, that doesn't need to be modified internally, to work.

I just can't get it to work. 🙂 Any thoughts on what I'm missing?

Attach Script seems to imply that, as long as the script exists, the Button can find it.

I also notice, that the tutorial, shows the word "Sprite" in the left-panel - but even though I renamed my child-scene SpriteScene, it displays as "Node2D" in the top-level Scene. I thought I followed the tutorial correctly... 🙂

One more difference:

In the tutorial, it shows a "script-icon", whereas mine doesn't. Does this mean there should be a script attached to the top node? Or is there something needed, to "expose" the Sprite script - maybe make it Public, or something?

  • Megalomaniak and DaveTheCoder replied to this.
  • At that point in the tutorial, the second scene should have a single node, Sprite, as the root. It doesn't have a child Label or child Sprite.

    Crawfish I also notice, that the tutorial, shows the word "Sprite" in the left-panel - but even though I renamed my child-scene SpriteScene, it displays as "Node2D" in the top-level Scene. I thought I followed the tutorial correctly...

    What name did you use when you saved your scene? Did you rename your node after you had initially saved the scene?

      Megalomaniak Ah, I named the file, but didn't double-click on the Node2D and rename it. Just did that, and got a different error message - so, progress. 🙂

      method in target node must be specified

      The name changed, so it looks closer to the tutorial, but there's still no "script" icon on it.

      Well, there needs to be a script to reference the method, some wheres and I think, yes, it needs to be local to the scene if you connect through the interface (rather than through script), though not necessarily to the top node.

      This is a pretty comprehensive video explaining it... and he describes your dilemma here @ 10:30
      ->

        ajay well, there is a script, on the movable Sprite, which is a child of the Node2D named-Sprite. It isn't clear how to connect to a child of a child, though. Which is what I think the tutorial is trying to do.

        Crawfish But all I get is "cannot connect signal, target method not found."

        I just tried that tutorial, and that step worked correctly. When I clicked the Connect button in the dialog, the script editor opened with the new function added at the bottom of Sprite.gd:

        func _on_Button_pressed() -> void:
        	pass # Replace with function body.

          DaveTheCoder I don't doubt it works, I've just done some minor thing that wasn't right. But what is the difference? It sounds like, from your description, that clicking Connect would add a new function. I've tried it both with, and without a function on the display Sprite (not Scene), and nothing happened. Are you manually attaching a script to the Scene, maybe?

          Anyway, my setup is almost, but not quite, like the tutorial - the only difference is, the Scene doesn't show a Script icon.

          Yep, that's the answer. Where the tutorial said "attach a script to Sprite.gd", I attached it to the actual Sprite - the thing that moves around - not the Scene. Wups.

          Just to confirm, it looks like the Signal communication, can only go to a script attached to the Node at the top of a Scene, and not any children of it?

          Nope, it's not the answer. Sigh... That top-level script isn't actually working to pause the Sprite-movement.

          In fact, I just confirmed that the tutorial did say the display-Sprite:

          At that point in the tutorial, the second scene should have a single node, Sprite, as the root. It doesn't have a child Label or child Sprite.

            DaveTheCoder Ah, now I see what I did - didn't start from scratch (like the tutorial said), and added a Sprite to a Scene. Many thanks for the explanations.

            So when I created a new Scene/Sprite, yes, the Connect did an auto-attach to the script.

            That does imply that only top-level Scripts, can receive signals from other Scenes? Is there a way that a child-object could get the signal, that is just more advanced than a tutorial would cover?

            Any script (actually node) can receive a signal from any other node. There may be limitations in connecting signals using the GUI, but you can also do the connecting in code.