How can I switch on/off the visibility of a global scene?

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


I need a global scene in my 2D game, therefore I made this to global in AutoLoad tab. But in this case this scene always visible, therefore I set its visibility to false in its _ready() function.
But how can I switch it back when I want to see again this scene?
I try this from the Start button of the title scene:

extends Button

onready var palya=preload("res://palya1.tscn")

func _process(delta):
	if Input.is_mouse_button_pressed(BUTTON_LEFT):
		var p=palya.instance()

but nothing happen. I use Godot engine 3.3. Somebody can help me?

:bust_in_silhouette: Reply From: Enfyna

You are creating a new scene instead of using your global scene. You can access your global scenes or scripts with their name. If your autoloaded scene name is palya1 then doing palya1.visible = true should be enough.

Hello Enfyna and thanks for your answer, but in this case I get a packed scene error message.
But I think, I forgot write “get_tree().get_root()” before “add_child()”…

Tomi | 2023-06-19 11:35

How did you write your code ? What is your global scene name ? If your global scene name is palya then this should work :

extends Button

func _process(delta):
    if Input.is_mouse_button_pressed(BUTTON_LEFT):

You dont add_child a global scene because it is already added.

Enfyna | 2023-06-19 11:44