Hi, i'm having issues on my beginner project.
In my project I I have a barracks.tscn from wich I instantiate RecruitScreen.tcsn that opens in a new window where the player can choose heroes to add to his party. After selecting heroes, the player can press the "buy" button to put the selected heroes in his party. I'm unable to figure out how to send a signal from the buy button back to a function in the original scene.
Do I instantiate the original scene once more from the RecruitScreen? Or is it possible to instantiate only the script carrying the funtion i'm trying to get to?
Alternatively is there maybe a more efficient way all togetter to do with i'm trying?

I've tried alot of tutorials but they all seem to focus on signalling within a scene.

Thanks in advance!

  • Dagunov replied to this.
  • maajkol All errors with (on base: 'null instance') mean that you are trying to access null instance, lets see...
    Try using get_node instead of find_child. I looked it up in the docs here.
    Also, to test if this works at all - comment out RecruitScreen.find_child("VBoxContainer/HBoxContainer/Hire").pressed.connect(on_buy_heroes) and check if your scene is creating.

    While debugging, you can view actual scene tree by pressing 'remote' up your nodes hierarchy. Try that!

    maajkol Hi! I am sure you can do what you want.
    To do this you need to connect to the button pressed signal via code, not editor. So if you instantiate RecruitScreen.tcsn somehow like this:

    var new_scene = recruit_scene.instantiate()
    add_child(new_scene)

    what you should do is add

    new_scene.find_child('PATH_TO_BUTTON').pressed.connect(YOUR_FUNCTION_NAME)

    Where PATH_TO_BUTTON can be something like HUD/BuyButton, and YOUR_FUNCTION_NAME can be something like on_recruit_scene_buy_pressed
    Hope this helps, please post any errors that are occurring next!

      Dagunov
      First of all, thanks for replying! i've got an "invalid get index 'pressed" (on base: 'null instance') error".
      I think I messed up the path to the button.

      var viewport_size = get_viewport_rect().size
      var RecruitScreen = load("res://tabs/RecruitScreen.tscn").instantiate()
      get_tree().get_root().add_child(RecruitScreen)
      RecruitScreen.find_child("VBoxContainer/HBoxContainer/Hire").pressed.connect(on_buy_heroes)
      RecruitScreen.set_size(viewport_size/2)
      RecruitScreen.set_position(viewport_size/4)

        maajkol All errors with (on base: 'null instance') mean that you are trying to access null instance, lets see...
        Try using get_node instead of find_child. I looked it up in the docs here.
        Also, to test if this works at all - comment out RecruitScreen.find_child("VBoxContainer/HBoxContainer/Hire").pressed.connect(on_buy_heroes) and check if your scene is creating.

        While debugging, you can view actual scene tree by pressing 'remote' up your nodes hierarchy. Try that!

          Dagunov
          I got it running using get_node instead of find_node.
          Thank you very much for helping me along!