#file-dialog #bevy #dialog

bevy_file_dialog

File system dialogs for loading and saving files using the Bevy game engine

10 releases (breaking)

0.9.0 Oct 6, 2025
0.8.0 Apr 26, 2025
0.6.0 Jul 14, 2024
0.5.0 Mar 11, 2024
0.1.0 Nov 24, 2023

#375 in Game dev

Download history 20/week @ 2025-08-23 18/week @ 2025-08-30 20/week @ 2025-09-06 20/week @ 2025-09-13 17/week @ 2025-09-20 15/week @ 2025-09-27 150/week @ 2025-10-04 62/week @ 2025-10-11 34/week @ 2025-10-18 20/week @ 2025-10-25 19/week @ 2025-11-01 66/week @ 2025-11-08 35/week @ 2025-11-15 50/week @ 2025-11-22 29/week @ 2025-11-29 6/week @ 2025-12-06

126 downloads per month

MIT/Apache

48KB
454 lines

bevy_file_dialog

crates.io docs.rs

A plugin for loading and saving files using system dialogs for the Bevy game engine.

Usage

See usage below for loading and saving and the examples for separate load/save dialogs. This example is also present in examples and you can run it with cargo run --example save_and_load.

use bevy::prelude::*;
use bevy_file_dialog::prelude::*;

struct TextFileContents;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        // Add the file dialog plugin
        .add_plugins(
            FileDialogPlugin::new()
                // allow saving of files marked with TextFileContents
                .with_save_file::<TextFileContents>()
                // allow loading of files marked with TextFileContents
                .with_load_file::<TextFileContents>(),
        )
        .add_systems(Startup, setup)
        .add_systems(
            Update,
            (
                dialog,
                file_loaded,
                file_saved,
                file_load_canceled,
                file_save_canceled,
            ),
        )
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
}

fn dialog(mut commands: Commands, keys: Res<ButtonInput<KeyCode>>) {
    // Ctrl+S - save file
    // Ctrl+O - load file

    if keys.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]) {
        if keys.just_pressed(KeyCode::S) {
            // save contents to selected file
            commands
                .dialog()
                .add_filter("Text", &["txt"])
                .set_file_name("hello.txt")
                .save_file::<TextFileContents>(b"hello".to_vec());
        } else if keys.just_pressed(KeyCode::O) {
            // read contents from selected file
            commands
                .dialog()
                .add_filter("Text", &["txt"])
                .load_file::<TextFileContents>();
        }
    }
}

fn file_loaded(mut ev_loaded: EventReader<DialogFileLoaded<TextFileContents>>) {
    for ev in ev_loaded.read() {
        eprintln!(
            "Loaded file {} with contents '{}'",
            ev.file_name,
            std::str::from_utf8(&ev.contents).unwrap()
        );
    }
}

fn file_load_canceled(mut ev_canceled: EventReader<DialogFileLoadCanceled<TextFileContents>>) {
    for _ in ev_canceled.read() {
        eprintln!("Text file content load canceled");
    }
}

fn file_saved(mut ev_saved: EventReader<DialogFileSaved<TextFileContents>>) {
    for ev in ev_saved.read() {
        match ev.result {
            Ok(_) => eprintln!("File {} successfully saved", ev.file_name),
            Err(ref err) => eprintln!("Failed to save {}: {}", ev.file_name, err),
        }
    }
}

fn file_save_canceled(mut ev_canceled: EventReader<DialogFileSaveCanceled<TextFileContents>>) {
    for _ in ev_canceled.read() {
        eprintln!("Text file content save canceled");
    }
}

File dialogs on Linux and BSDs

You can use one of the two backends on linux to create file dialogs that is specified with features, either gtk3 or xdg-portal. By default bevy_file_dialog uses the default provided by rfd which is xdg-portal. You can change this by specifying the correct features in your Cargo.toml:

bevy_file_dialog = { version = "*", default-features = false, features = ["gtk3"] }

More information in rfd docs, the information there matches bevy_file_dialog.


bevy bevy_file_dialog
0.17 0.9.0
0.16 0.8.0
0.14 0.6.0
0.13 0.4.0 - 0.5.0
0.12 0.1.0 - 0.3.1

Dependencies

~44–88MB
~1.5M SLoC