Building Your First Plugin

Building Your First Plugin

The Foresight SDK’s modular architecture makes it incredibly fast to add new behavior to the client. In this guide, we’ll build a minimal “Hello World” plugin that registers a simple Bevy system.

1. Create a New Crate

First, create a new Rust library crate in the plugins/ directory.

cargo new plugins/fdk_plugin_hello_world --lib

Update the Cargo.toml to include the fdk dependency:

[package]
name = "fdk_plugin_hello_world"
version = "0.1.0"
edition = "2024"

[dependencies]
fdk = { path = "../../crates/fdk" }
bevy = { version = "0.16", default-features = false }

2. Implement the Plugin

In src/lib.rs, define your plugin by implementing the plugin trait.

use fdk::prelude::*;
use fdk::libs::bevy::prelude::*;

pub struct HelloWorldPlugin;

impl FoundryPlugin for HelloWorldPlugin {
    fn build(self, app: &mut FoundryPluginBuilder) {
        // Register a standard Bevy plugin
        app.add_plugins(MyEnginePlugin);
    }
}

struct MyEnginePlugin;

impl Plugin for MyEnginePlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Update, hello_system);
    }
}

fn hello_system(time: Res<Time>) {
    // This system runs every frame in the client engine
}

// Export the plugin so the client can discover it
fdk::export! {
    type HelloWorldPlugin;
}

3. Building an Application

To create a client application, you use the Foresight SDK application builder. A typical SpatialDrive implementation is built using the Foresight SDK:

use fdk::prelude::*;

fn main() {
    FoundryApp::new()
        .add_plugins(HelloWorldPlugin)
        .add_plugins(fdk::plugins::volumetrics::VolumetricsPlugin)
        .run();
}

Next Steps

Now that you’ve seen how to hook into the engine, you can start exploring more advanced topics: