Script in main scene does not run if I click the "run project" button, but it does work if I click "run current scene"

Godot Version

4.5.1-stable

Question

I made a scene for a pause menu, which has a script attached, which makes the pause menu visible when I press the escape key. I can then add that scene to another scene in order to use it there. This works as expected, even in my main scene, except for when I run the project by clicking the “run project“ button. Then it loads the main scene, but the pause menu does not appear when pressing escape. However, it works if I just select the main scene and click “run current scene“. I think the issue is that it is not running the script at all.

Here is the script (though I doubt the script is relevant, since I don’t think it’s being run at all):

extends Control

func _ready():
	hide()
	$AnimationPlayer.play("RESET")

func resume():
	get_tree().paused = false
	$AnimationPlayer.play_backwards("blur")
	
func pause():
	get_tree().paused = true
	show()
	$AnimationPlayer.play("blur")
	
func escape():
	if Input.is_action_just_pressed("escape") and !get_tree().paused:
		pause()
	elif Input.is_action_just_pressed("escape") and get_tree().paused:
		resume()

func _on_resume_pressed() -> void:
	resume()

func _on_settings_pressed() -> void:
	pass # Replace with function body.

func _on_quit_pressed() -> void:
	get_tree().quit()


	
func _process(delta):
	escape()


func _on_animation_player_animation_finished(anim_name: StringName) -> void:
	if get_tree().paused == false:
		hide()

I’m not sure if this is related or not, but I also noticed that a TextEdit in my main scene was sized correctly, but appeared much smaller than it should when, and only when, the game was run through the “run project“ button.

Does anyone have any tips as for what I should do to figure out what is causing these things to work differently when run in the “run project“ vs “run current scene“ modes? Any other info I should add to this post to make it easier to debug?

Run project should just run the scene you’ve marked as your main scene. It’s like using run current scene on your main scene.

What is your main scene exactly?

Solved it. Turns out, that although the main scene was set to the scene I wanted, I accidentally had an old duplicate of the scene, which is what I added the script to (and modified the size of the TextEdit in). I always seem to spend hours on tiny issues like this, just to figure out the answer immediately after I ask for help :laughing:

1 Like