Has anyone used Bevy ECS for backend / server-side architecture? #21820
Replies: 4 comments
-
|
I really don't understand why you want to use the ECS architecture (specifically for gaming application development) for your problem. If Unity or other tools are commonly used for those problems, Bevy can certainly handle them. However, in my opinion, current game engines focus more on GUI, GPU, UI, etc., rather than data entry streams. Other Rust libraries specializing in web, server, etc., have been created differently from Bevy. If my assessment is incorrect, please provide further feedback. Thank you! |
Beta Was this translation helpful? Give feedback.
-
|
You can implement your solutions using the following libraries and frameworks: Warp, Tokio, ReqWest, etc. They are more suitable for backend and server-side development, rather than focusing solely on the main thread (UI thread) like game engines. There are many patterns for developing RESTful APIs, and ECS is specialized for games, not entirely suitable for backend or server development. |
Beta Was this translation helpful? Give feedback.
-
|
bevy_ecs (or any ecs for that matter) can be used as an in memory database, so you can use it as a server. There are a few project where it's used as the backend server for games, to allow entity synchronisation. There's also someone that made an http server with bevy_ecs, but that was more a toy/proof of concept. Where bevy_ecs is a bit hard to use as a backend server is:
|
Beta Was this translation helpful? Give feedback.
-
|
Hello @arrietybeu, I don't know the goal you want to achieve but I think I can support. I am using a way to get bevy working with tokio for my authoritative server. In the example below I am using to create an UDP connection. What you need from bevy:
What you need from tokio:
The flow is the following:
Code example (server): #[derive(Resource)]
pub struct NetworkOutboundChannel(pub mpsc::Sender<{your_data_channel_here}>);
#[derive(Resource)]
pub struct NetworkInboundChannel(pub mpsc::Receiver<{your_data_channel_here}>);
#[tokio::main]
async fn main() {
/* ================== TOKIO APP ================== */
let mut connection = Connection::new("127.0.0.1:8080".to_string()).await;
connection.inbound_process().await;
connection.outbound_process().await;
/* ================== BEVY APP ================== */
let mut app = App::new();
app.add_plugins(MinimalPlugins);
app.insert_resource(NetworkInboundChannel(connection.inbound_rx));
app.insert_resource(NetworkOutboundChannel(connection.outbound_tx));
}
// ...
loop {
let mut buf = [0; 1024];
socket.recv_from(&mut buf).await {
// ...
inbound_tx.send(net_channel_data);
// ...
}
}
// ...
loop {
while let Ok(channel_data) = outbound_rx.try_recv() {
// ...
}
}In your bevy pub fn fixed_update_network_inbound(
mut net_inbound_channel: ResMut<NetworkInboundChannel>,
) {
while let Ok(channel_data) = net_inbound_channel.0.try_recv() {
// process the inbound {your_data_channel_here} in bevy systems
}
}
pub fn fixed_update_network_outbound(
net_outbound_channel: Res<NetworkOutboundChannel>,
) {
// send to the outbound channel (in case of UDP servers)
net_outbound_channel.0.try_send({your_data_channel_here})
}In case you want to use a
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I’m exploring whether the standalone bevy_ecs crate is a good fit for building a backend server (no rendering, no Bevy app).
I want to use ECS to manage player sessions and run server logic on a fixed tick loop.
Before I go deeper, I’d like to ask:
Has anyone used bevy_ecs for backend or server-side projects?
Are there any known limitations when using it outside the Bevy engine?
Is it a good choice compared to other ECS libraries like hecs or legion?
Any experience or advice would be appreciated. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions