1 unstable release
new 0.1.0 | Dec 23, 2024 |
---|
#6 in #netcode
480KB
500 lines
Bevy Replicon Renet2
An integration of bevy_renet2
as a messaging backend for bevy_replicon
.
Compatible versions
bevy_replicon_renet2 | bevy_renet2 | bevy_replicon | bevy |
---|---|---|---|
0.1.0 | 0.1.0 | 0.29 | 0.15.0 |
0.0.9 | 0.0.7 | 0.29 | 0.15.0 |
0.0.5 | 0.0.4 | 0.26 | 0.14.0 |
0.0.4 | 0.0.3 | 0.26 | 0.14.0 |
0.0.3 | 0.0.3 | 0.25 | 0.14.0 |
lib.rs
:
Provides integration for bevy_replicon
for bevy_renet2
.
Getting started
This guide assumes that you have already read quick start guide from bevy_replicon
.
All Renet API is re-exported from this plugin, you don't need to include bevy_renet
or renet
to your Cargo.toml
.
Renet by default uses the netcode transport which is re-exported by the transport
feature. If you want to use other transports, you can disable it.
Initialization
Add RepliconRenetPlugins
along with RepliconPlugins
:
use bevy::prelude::*;
use bevy_replicon::prelude::*;
use bevy_replicon_renet2::RepliconRenetPlugins;
let mut app = App::new();
app.add_plugins((MinimalPlugins, RepliconPlugins, RepliconRenetPlugins));
Plugins in RepliconRenetPlugins
automatically add renet2
plugins, you don't need to add them.
If the transport
feature is enabled, netcode plugins will also be automatically added.
Server and client creation
To connect to the server or create it, you need to initialize the
RenetClient
and NetcodeClientTransport
or
RenetServer
and NetcodeServerTransport
resources from Renet.
Never insert client and server resources in the same app for single-player, it will cause a replication loop.
This crate provides the RenetChannelsExt
extension trait to conveniently convert channels
from the RepliconChannels
resource into renet2 channels.
When creating a server or client you need to use a ConnectionConfig
from renet2
, which can be initialized like this:
use bevy::prelude::*;
use bevy_replicon::prelude::*;
use bevy_replicon_renet2::{renet2::ConnectionConfig, RenetChannelsExt, RepliconRenetPlugins};
let channels = app.world().resource::<RepliconChannels>();
let connection_config = ConnectionConfig::from_channels(
channels.get_server_configs(),
channels.get_client_configs(),
);
For a full example of how to initialize a server or client see the example in the repository.
Dependencies
~57–97MB
~1.5M SLoC