0 votes

A pressed() signal on a button has this code:

if get_tree().current_scene.filename == "res://Scene1.tscn":
    $ScrollContainer/Panel/AudioStreamPlayer.play()
else:
    $Panel/AudioStreamPlayer.play()
get_tree().change_scene("res://Scene2.tscn")

The sound doesn't always plays when pressing a button and changing the scene.

Godot version 3.4
in Engine by (64 points)

1 Answer

0 votes

Write
print(gettree().currentscene.name)
inside _ready() and call the _ready() in the pressed() signal.... and check what does it print: does it only sometimes print the Scene1 or always? If it is always Scene1, then there is something wrong with the sound path. If it isn't always Scene1, then there is something wrong with the code which switches to that scene.

Like:

func _ready():
>print(get_tree().current_scene_name)

func pressed()
>_ready()
>if get_tree().current_scene.filename == etc......
by (18 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.