How to get the name of the currently active scene from a player script without changing the scene

Godot Version 4.0

I have been creating a platformer similar to Doodle Jump. I am able to get all the main game mechanics to work and I have a few ideas for some game modes for side content. I use an enum to list out the possible game modes and an exported variable that is supposed to grab and change the current game mode when needed. I have made a function that checks the player’s current game mode and alters the player’s abilities if the current game mode is equal to the desired one. Each game mode has their own dedicated scene, and because player is included in all of them, I’m asking for a way for Godot to read the currently active scene and change the currentMode variable to be equal to whichever scene was selected by the player. Here is the code for my Player script that uses the Jetpack game mode as an example:
Screenshot 2024-04-09 143825

The name of the scene is in a property called name

In order to get it you could traverse the parent child hierarchy in many ways (like get_parent().name). If you want it readily available I would create an auto load, or a static class, that knows what scene is “active”.

Scene loader

MyAutoload.set_active_scene_name(scene.name)

Player

Var active_scene_name = MyAutoload.get_active_scene_name()

Oh… I was able to figure it out… the function was never called, so it never ran. threw the function in physics process, and that solved the issue. Thank you for your help though!

Probably more easily you can set the group “active_scene” in your scenes, then just get_nodes_in_group(“active_scene”) to get the scene which is running.