How to make soundplayer play while a scene is automatically "paused" for a few seconds?

Godot Version

4.1

Question

i added a script to my scene that makes it “paused” (or frozen) for a few seconds and now i need to make a sound play while it is paused

the script uses a get_tree with a create_timer to make it “paused”

here is the code:

extends Node
@onready var gamestart_player = $soundPlayers/gamestart_player




func _ready():
	get_tree().paused = true
	await get_tree().create_timer(4.43).timeout
	get_tree().paused = false

Assuming this node is set to process always or while paused, could you use gamestart_player.play() before/after pausing?

i can make it play after pausing but i need it to be playing when its pausing

then before pausing.

func _ready():
	get_tree().paused = true
	gamestart_player.play()

	await get_tree().create_timer(4.43).timeout
	get_tree().paused = false

that code still makes the sound play after the pause though

is the node set to process always or while paused?

its set to “inherit”

Set it to “Always” for good measure.

alright

so i tried and the sound is playing but it doesnt pause anymore

Nodes start set to “Inherit” process mode, meaning they take their parent’s. If this node is your scene root then all the children will also process during pauses. Maybe you want to separate this node, or set some of the children to process_mode “Pausable”

the node is the scene root
ima try to make it a seperate node

i made a new node inside the original node and connected the script that has the pause to the new node i made, but the sound still plays after the pause, maybe i could make the rest of the nodes’s modes into “pausable”

I think I would need a scene tree with any process mode’s you’ve changed from “Inherit” marked to help more

here it is, nodes with process modes as “Inherit” are marked in red boxes
the “get ready!” node is the new node i made to connect the script to

You would need your “gamestart_player” node to be a child of “get ready!” for it to inherit the Always processable state. If the sound player is Pausable/Inherit then the sound it plays will pause.

alright

putted the “gamestart_player” node inside “get ready!” as a child
its working, thanks

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