Copying an ogg file in XR from res:// to user://

Godot Version

4.2.1

Question

I am trying to create a custom level which requires moving the song file to a final level folder. This is a VR game and read/write permissions are on. I am very confused why the code below isn’t copying.

var song_copy_error = DirAccess.copy_absolute(“res://Levels/draft/%s/song.ogg” % original_level_name, “user://Levels/complete/%s/song.ogg” % level_name)

I know user://Level/complete/%s exists and the saving the level with the line below works fine. Song_copy_error returns 12, and any attempts to open “res://Levels/draft/%s/song.ogg” with diraccess or fileaccess fail. This could be because I already loaded the file to help in making the level but I don’t know how that would affect anything.

save_level_error = ResourceSaver.save(level_file, “user://Levels/complete/%s/level.tres” % level_name)

Any help would be very much appreciated.

When you export the game the original files (png, tscn, wav, ogg,…) aren’t exported directly but only the .remap (in the case of text resources that get compressed to binary: tscn, tres,…) or the .import files are (which point to the correct remapped/imported file inside the .godot folder).

DirAccess and FileAccess just read the directory/file directly and don’t take those files into account (it won’t follow the remap or import target file)

When running form the editor it’s looks fine because both files are present (the .import and the original file) But when running it in a exported project it won’t work.

In theory if you add the original file in the Filters to export non-resource files/folders in the export dialog it should export the original file too Exporting projects — Godot Engine (stable) documentation in English But I’ve been not able to get it to work.

You could save the Resource itself in the user:// folder like:

extends Node


func _ready() -> void:
	save_ogg('res://Wacky Waiting.ogg', 'user://Wacky Wating.oggvorbisstr')


func save_ogg(from:String, to:String) -> void:
	var ogg = load(from)
	var result = ResourceSaver.save(ogg, to)
	printt(result, error_string(result))

But it’s not an ogg file so the user won’t be able to play it with an external program. The extension is important or it will fail saving it.

This solution works for me but I did some digging into these .oggvorbisstr files and they seem to be how Godot compresses .ogg file during export.

I also found a third-party tool to convert .oggvorbisstr files back to .ogg files at Release v0.6.0 · bruvzg/gdsdecomp (github.com)
It’s a reverse-engineering toolset that has the function and I heard it worked for someone else.