how to detect crrent scene godot

func _process(delta float64):
    var currentScene = get_tree().get_current_scene()
    if currentScene != null:
        print("Current Scene: ", currentScene.get_name())
    else:
        print("No scene currently active")

Explanation: 1. func _process(delta float64): - This function is called every frame. It allows continuous monitoring and updating of the game state.

  1. var currentScene = get_tree().get_current_scene() - Retrieves the current scene that is active within the game using the get_current_scene() method from the scene tree (get_tree()).

  2. if currentScene != null: - Checks if there is an active scene. If currentScene is not null (i.e., a scene is active), it proceeds with the next step.

  3. print("Current Scene: ", currentScene.get_name()) - Prints the name of the current scene using get_name(). This line will output the name of the active scene to the console.

  4. else: - If there is no active scene (i.e., currentScene is null), this block executes.

  5. print("No scene currently active") - Outputs a message indicating that there is no active scene to the console.