How do you save movie (using Movie Maker) to a file with a base name including the timestamp

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tonebacas

When I turn on the Movie Maker Mode, I want to save a new video in the current project’s folder; the file should have its name based on the instant I start running the scene.

I understand I can use the Project Setting “editor/movie_writer/movie_file” option to set the file path, but I don’t know how to change this option programmatically, before running the scene.

I am able to change and save this setting at runtime once the scene is running, but the option isn’t taken into account for that session, only taking effect on the next time I run the scene.

At the root node of my project:

func _init() -> void:
	var base_project_path := ProjectSettings.globalize_path("res://")
	var time_str := Time.get_datetime_string_from_system().replace(":","_")
	var movie_path := base_project_path + time_str + ".avi"
	ProjectSettings.set_setting("editor/movie_writer/movie_file", movie_path)
	ProjectSettings.save()

Using this code, when I run the scene at 13:30:00, the Editor starts writing the video file to whatever path was previously set, then my code changes it to “project_dir/2023-02-16T13_30_00.avi”.

The next time I run the scene, the new video gets saved to that path, then the option is changed again according to the code in the sample, and so on.

I would like to set the name of the video being recorded, based on the timestamp of the instant when I run a scene. If I could change the “editor/movie_writer/movie_file” setting at a previous step before running a scene, I could do it using the sample code, but I don’t know how to do this.

Just hid my initial answer as I realize you’re already aware of what I pointed out…

jgodfrey | 2023-02-16 21:16

:bust_in_silhouette: Reply From: tonebacas

I figured I could use an EditorScript (EditorScript — Godot Engine (stable) documentation in English) to execute the code that changes the Project setting “editor/movie_writer/movie_file”. I just have to remember to select the script from the script panel and run it manually before running the scene with Movie Maker on.

The code should look like this:

@tool
extends EditorScript

    func _run():
        var base_project_path := ProjectSettings.globalize_path("res://")
        var time_str := Time.get_datetime_string_from_system().replace(":","_")
        var movie_path := base_project_path + time_str + ".avi"
        ProjectSettings.set_setting("editor/movie_writer/movie_file", movie_path)
        ProjectSettings.save()