How to create a Game Server and Client? #15446
-
My initial approach was to adapt my standalone game into a game server by removing all the rendering, windowing, and input plugins, and adding a plugin that serializes the world and sends it to the clients. All entity spawning, physics, and game logic will be done on the server. The client would have no logic plugins and would create a window, a camera, a renderer, and a way to receive and deserialize the "remote_world" and synchronize it with the "local_world". It would also serialize and send input events to the server. I tried to make a minimal example, that uses RON over WebSockets, but reached a few hurdles:
Am I approaching this the wrong way? What is a simple way to serialize/deserialize and send/receive the resources and components between a server and client? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Definitely look into bevy renet! You can also look into some guides to multiplayer in Bevy: Multiplayer in Rust using Renet and Bevy. I think your approach is not that bad, but you definitely can NOT serialize the whole world. I would recommend having specific components, that show a plugin to sync specific serializable components: #[derive(Component)]
struct SyncTransformComponent;
fn send_components(
query: Query<(Transform, Entity), With<SyncTransformComponent>,
// ....
) {
// serializing logic with serde and for example bincode
// ...
// sending logic
} I wrote this example out of my head, but I hope you get the idea. With this logic, you could for every specific entity decide, which data to sync, and which data not to sync. For example, you could sync a initialization component, that tells all clients, which mesh type of enemy a entity is, but leave the actual mesh at the server. Also, you could very easily distinguish from client side stuff and server side stuff, just by not giving the entities the But because bevy currently does not aims towards good multiplayer support (as shown here), you have to understand that you will have to implement a lot of stuff by your own. |
Beta Was this translation helpful? Give feedback.
Definitely look into bevy renet! You can also look into some guides to multiplayer in Bevy: Multiplayer in Rust using Renet and Bevy. I think your approach is not that bad, but you definitely can NOT serialize the whole world. I would recommend having specific components, that show a plugin to sync specific serializable components:
I wrote this example out of my head, but I hope you get the idea. With this logic, you could for every specific entity decide, …