Flickering between scenes (pause menu)

Godot Version

4.3.stable

Question

I created a pause menu for the first time in Godot. I made it its own scene. While it works to some degree, it flickers between the game scene and the pause scene, though it will eventually land one of the scenes. Sometimes it’s the right one, sometimes it’s not. If I hold the assigned button down, it will flicker back and forth as long as it is pressed. Is this something funky with my inputs? Or something else? Any suggestions would be greatly appreciated. I’ve added the relevant code below.

Player script (in process)

        #checking if game is unpaused and if the pause button has been pressed
	if Input.is_action_pressed("selection_screen") and get_tree().paused == false:
                #pause the game, switch to pause screen
		get_tree().paused = true
		get_tree().change_scene_to_file("res://select_screen.tscn")

Pause screen:

func _process(delta: float):

        #checks if game is paused and pause button is pressed
	if Input.is_action_pressed("selection_screen") and get_tree().paused == true:
                #unpause the game, go back to the current scene
		get_tree().paused = false
		get_tree().change_scene_to_file(Globals.current_scene)

Also, if you know a better way to do this, by all means let me know. Always looking for new tricks! :grin:

this is the reason why, changing scene will cause flicker because you are using the basic change_scene_to_file, there’s always a little gap between changing scene, so your best you can do is to actually has the pause scene instantiated in front of the player/menu
or simply set view visible or not visible the pause scene

The solution ended up being super simple. Changed Input.is_action_pressed to Input.is_action_just_pressed and it’s a smooth transition now! Go figure :upside_down_face:

Also, thanks @zdrmlpzdrmlp for your help, I tried out your way as well!

1 Like

for small scene, it should be fine, but when you have bigger sized scene, you dont want to use the change_scene_to_file. it will show grey screen on switching in-between.

1 Like

this is indeed an issue yeah, i just realized it too

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