Expand description
Provides integration for bevy_replicon
for bevy_renet
.
§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 renet_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_renet::RepliconRenetPlugins;
let mut app = App::new();
app.add_plugins((MinimalPlugins, RepliconPlugins, RepliconRenetPlugins));
If you want to separate the client and server, you can use the client
and server
features (both enabled by default),
which control enabled plugins. These features automatically enable corresponding features in bevy_replicon
.
It’s also possible to do it at runtime via PluginGroupBuilder::disable()
.
For server disable RepliconRenetClientPlugin
.
For client disable RepliconRenetServerPlugin
.
Plugins in RepliconRenetPlugins
automatically add renet
plugins, you don’t need to add them.
If the renet_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.
For steam transport you need to activate the corresponding and use its transport resource instead.
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 renet channels.
When creating a server or client you need to use a ConnectionConfig
from renet
, which can be initialized like this:
use bevy::prelude::*;
use bevy_replicon::prelude::*;
use bevy_replicon_renet::{renet::ConnectionConfig, RenetChannelsExt, RepliconRenetPlugins};
let channels = app.world().resource::<RepliconChannels>();
let connection_config = ConnectionConfig {
server_channels_config: channels.get_server_configs(),
client_channels_config: channels.get_client_configs(),
..Default::default()
};
For a full example of how to initialize a server or client see the example in the repository.
§Replicon conditions
The crate updates the running state of RepliconServer
and connection state of RepliconClient
based on the states of RenetServer
and RenetClient
in PreUpdate
.
This means that replicon conditions won’t work in schedules
like Startup
. As a workaround, you can directly check if renet’s resources are present. This may be resolved
in the future once we have observers for resources
to immediately react to changes.
Re-exports§
pub use bevy_renet::renet;
Modules§
Structs§
- Plugin group for all replicon plugins for renet.
Traits§
- External trait for
RepliconChannels
to provide convenient conversion into renet channel configs.