[Solved] Signals from instanced scene - can you help?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Giovanni “Johnny” Co

Hello, I find myself stuck and I was wondering if anyone could point me in the right direction. I am making a game where the player basically pops party baloons with their mouse/touch. I have scene made up with an area2d, a sprite, and a label. When the user clicks on a ballon the baloon pops. [1] I then instance a number of baloons (scenes) in my main scene and clicking on the baloons has no effect [2] I would like to be able to pop each instance of the balloon independently when I run the main scene. It’s a couple of days I am trying to look around the documentation and YT videos but it seems that I can not wrap this up. I am quite new to Godot and I am not particularly smart, so any help will be really appreciated. Be safe, be well, ciao from Italy. Thank you

[1] baloon scene - Album on Imgur [2] main - Album on Imgur

:bust_in_silhouette: Reply From: Sween123

Use “Button” can help you to detect mouse inputs on the ballons, it’s quite good.
So, for a ballon scene, for the graphic part, you can just use a sprite like what you used. For detecting mouse clicks that will make ballons pops, create a Button node, turn on the property “flat” (So the graphic of a button which we normally use won’t show up). On the right side of the editor there are the Inspector and Node. Go to node and connect the signal “pressed” to the ballon. (Remember to attach a script to the ballon node first) (A ballon scene may look like this: Parent-Node2D, Children-Button,Sprite)
In code, you’ll see a newly added function, which is the function that will be called when you click on the ballon. Inside this function, you can add code like: ballon_pop() where ballon_pop() is a function you created that will destory the ballon. (Using free() or queue_free() will remove the node)
Changing the size of the Button determines the region which mouse click is valid for this very ballon.

The main idea the Godot uses is about nodes, the world is a scene tree. There are parent node and child nodes, just like in a family, there are parents, children, brothers and sisters, and we use functions like get_node("/root/World")(path from the root) or get_node("Button")(A relative path to where the script is attached), get_parent(), etc. to access differents nodes in the scene tree.
Go to Godot docs and you can check out what methods and signals different nodes have and what they do. (ctrl + click in code can directly bring you into the docs that explain what you just clikced)

For fast instancing child nodes, you may want to use add_child(node) in code. Use a for loop or so to fast generate lots of instances. When there are lots of instances, you don’t want to add them by hand.

Thank you for your comment. Please see my answer below for further details.

Giovanni “Johnny” Co | 2020-03-17 23:33

:bust_in_silhouette: Reply From: Giovanni “Johnny” Co

Thanks to the contribution of fdwk on #godotengine on IRC, I now understand that the the issue in my project is not due to a misunderstanding of the signals system but to a yet to be discovered issue related to a MarginContainer node or its child TextureRect node included in my Main scene which is preventing the correct functionality of my signal chain.
If interested you can find below a small project I have implemented as a proof of functionality of a signal emitted from an instantiated object and processed in the main scene.

As you can see everything works seamlessly with no issues at all.

Thank you for reading.

Popping nodes scene

Thank you for sharing this information. I was able to solve a similar issue I had by changing the Filter property in the Mouse section of the TextureRect to IGNORE.

EyCiYo | 2023-04-03 17:50