The object I need doesn't become invisible

Godot v4.4.1.stable.steam

Here is my script:
extends Button

@onready var MainMenu = $“../../..”
@onready var animation_player = $“../../../../AP_scene1”
@onready var interact = $“../../../../interact”

func _ready() → void:
interact.visible = false
MainMenu.visible = true

func _on_pressed() → void:
# Удаляем узел MainMenu
MainMenu.visible = false

# Запускаем анимацию sub_1
animation_player.play("sub_1")

func _on_ap_scene_1_animation_finished(anim_name: StringName) → void:
if anim_name == “sub_1”:
interact.visible = true

Why doesn’t the MainMenu element become invisible? The only thing I could do was to remove this element from the scene, but then the interact element does not appear.

Hi,

MainMenu is set invisible in _on_pressed(), which leads me to think that this function may not be called. I suppose it’s meant to be connected to the button signals, have you made sure that’s done properly?

To check if the function is called, you can add a print inside of it:

func _on_pressed() → void:
    print("_on_pressed() called")
    MainMenu.visible = false

Yes, the function is being called, everything is connected correctly

Okay, in that case, either the MainMenu is correctly set to invisible but something sets it back to visible afterward, or, you’re not affecting the correct node.
Could you check both of these things?

I was able to fix the problem! I’m not making the MainMenu invisible, but the CanvasLayer, I’ll explain in more detail: I have a control type element in the scene called “MainMenu”. Buttons and the name of the game were attached to it, which I wanted to hide, however, a Label was also attached to this element, which was animated (some kind of titles) and despite the fact that MainMenu was specified in the script made the titles invisible, which are already invisible.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.