How to check if "Run Project" or "Run Current Scene" is being executed?

Godot Version

4.4

Question

I have a scene, let’s say “my_farm” which contains a test_case function that will be executed in the _ready() function. As for testing purpose, I will use “Run Current Scene” to specifically test just this scene and run the test_case() which creates various other scenes such as animals, crops, etc. for testing into the farm.

After finish testing, I commented the “test_case” function call in _ready() function, and run the game from the title menu scene instead.

Whenever I want to do some more testing, I will uncommented the “test_case” once again, but is there a better way like this? Is it possible to check whether “my_farm” scene is the one being executed as the first scene? This is so I could do something like this pseudocode here:

func _ready() -> void:
   if this_scene_is_being_ran_from_run_current_scene_in_the_editor :
      test_case()

Help > Programming

You could try checking if SceneTree.current_scene is the my_farm scene or not like:

func _ready() -> void:
   if get_tree().current_scene == self:
      test_case()

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