How to set Panel to invisible when certain Area2D is entered

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

Hi (I am a newbie and wasn’t sure how to add images here so if they won’t show properly I added links to my drive)
I created Panels with shared script and attached different sprites as child nodes to each one:

https://drive.google.com/file/d/1elgQ6wspdnJWtg69JoS7H8vl4DjmCN8W/view?usp=sharing

I wrote the code to make the Panels react to where the mouse drags/drops them (alongside with their sprites).

Afterwards I also added Area2D to the scene.
My goal is to make the player drag a panel to this Area2D and when that happens, the visibility of this specific panel (and its child nodes) should turn to false.
Here is what I tried:

https://drive.google.com/file/d/1ZX8XvmcFZrIuCAj0UOchlNa6mvskMaJ-/view?usp=sharing

But this is what keeps happeniing when I run the game:

https://drive.google.com/file/d/1Ya2ctAicJsf7Yhc1isRwv0D33Czy79LS/view?usp=sharing

I know the problem is in the line
Panel.visible = false
But I don’t know how to write it correctly.

I will be happy for any help.

:bust_in_silhouette: Reply From: Inces

Hehe it is actually funny and tricky mistake.
You call Panel.visible property, but the Panel You are calling is not your Panel himself - You never gave a name nor reference to it. Instead You are calling whole Panel class, grant blueprint for all Panels out there. So just stop calling it, and only do :

visible = true

or

self.visible = true

Oh my, it worked thank You :smiley:
I thought if I use just “visible/self.visible” it will reffer to the paperArea2D since it’s the node that calls the invisible() function, but somehow it knows I meant the panel (I still don’t know how completely, but that’s okay, I am super thankful for the help).

But I wonder why does the game print two “triangle-invisible” strings in the output: One when it’s supposed to, and one on the very beginning immediately after the game starts running…

Alena | 2022-02-06 20:27

You are welcome :slight_smile:
I rarely use this signal, but most likely visibility is automatically set from false to true when node is instanced

Inces | 2022-02-07 15:30

Hi again.
I am really sorry to keep writing but I had another problem (which I should have seen coming but just thought of it today):

Is there a way to make another node (let’s say Sprite - I called it “trianglePaper”) - that I put on invisible by default - set visible after the dragTriangle sprite’s visibility has changed?

https://drive.google.com/file/d/1JE3OGwdDgTLS1VCKoumvfyHoemWpUaya/view?usp=sharing

I would put this line under the
func _on_dragTriangle_visibility_changed():
instead of
print(“triangle-invisible”)

I tried to call a group in which both of these sprites (and the Panel with the script) are and then write the specific function about changing visibility to true on the scirpt of a sprite that I want to appear(aka trianglePaper):
https://drive.google.com/file/d/1nbUXRxdyc_fdEBtOBFoKcHAF2M1rT6LV/view?usp=sharing

https://drive.google.com/file/d/1jViptecPwDwvhG6n1-PTSWO47GvDGXWV/view?usp=sharing

But it didn’t work.
Isn’t there a way to set the visibility of a node to false/true alongside with reffering to what node I mean?

Thanks for any response/help in advance. I really try to figure things out on my own but I don’t know how to continue without solving this.

Alena | 2022-02-07 19:13