Reference Article
One of Bevy's core principles is modularity. All Bevy engine features are implemented as plugins - collections of code used to modify applications. This includes internal features such as renderers, but the game itself is also implemented as a plugin! This allows developers to choose the features they want. Don't need UI? Don't register the UiPlugin. Want to build a headless server? Don't register the RenderPlugin.
This also means that you are free to replace any components you don't like. If you feel it's necessary, you are welcome to build your own UiPlugin, but if you think it's useful, consider contributing it to Bevy!
Those that are not contributed to Bevy but released separately are third-party plugins. These are useful and easy-to-use plugins created by other developers that can help you avoid reinventing the wheel. To use them, all you have to do is:
- Find third-party Bevy plugins (such as those on the assets page).
- Add them as dependencies to your Cargo.toml [dependencies].
- Import code definitions from the crate (like ) to add items to your workspace. use third_party::prelude::*;
- Add the plugins to your app (e.g. ). app.add_plugins(third_party_plugin)
However, most developers don't need a customized experience, they just need an easy "full engine" experience. For this, Bevy provides a set of DefaultPlugins.
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.run();
}
cargo run
Next, implement a plugin yourself and print "Hello World!"
use bevy::prelude::*;
// To better organize, let's move all the "hello" logic into a plugin. To create a plugin, we just need to implement the Plugin interface. Add the following code to your file: main.rs
pub struct HelloPlugin;
impl Plugin for HelloPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, hello_world);
}
}
fn main() {
App::new()
.add_plugins((DefaultPlugins, HelloPlugin))
.run();
}
fn hello_world() {
println!("HelloWorld!")
}
cargo run