How to get a scene's filename from an autoloaded file?

Godot Version

4.2.2

Question

Hello, I am trying to make a Godot FPS game with a save and load system akin to what you would find in most shooters. E.X: Doom and Quake.

I am using resources and I am trying to create a system that will load the scene the player saved on. Note: I am already saving the player attributes, enemies, etc separately. I am not interested in saving the state of the scene, just which file it is.

I wanted to use the filename to add in this functionality, but this has not worked:

saveData.level = get_tree().current_scene().filename
Results in: ā€œInvalid get index ā€˜filenameā€™ (on base: ā€˜Node3D (level.gd)ā€™).ā€

Butā€¦

saveData.level = get_tree().current_scene()
Results in: ā€œInvalid get index ā€˜filenameā€™ (on base: ā€˜Node3D (level.gd)ā€™).ā€

Does anyone know how I can properly save a reference to which scene is currently being run?

Thank you in advance!

Whoops, just realized you must use the following in the most recent version of Godot:

ā€œget_tree().current_scene.scene_file_pathā€

1 Like

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