Crate bevy_replicon_renet2

Source
Expand description

Provides integration for bevy_replicon for bevy_renet2.

§Getting started

This guide assumes that you have already read the quick start guide for bevy_replicon.

§Modules

Renet2 API is re-exported from this crate under renet2 module. Features from bevy_renet2 are exposed, which also re-export the corresponding transport modules. Like in bevy_renet2, the netcode transport is enabled by default.

So you don’t need to include bevy_renet2 or renet2 in your Cargo.toml.

§Plugins

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));

Similar to Replicon, we provide client and server features. These automatically enable the corresponding features in bevy_replicon.

The plugins in RepliconRenetPlugins automatically include the renet2 plugins, so you don’t need to add them manually. When a transport feature is enabled, the netcode plugins will also be added automatically.

§Server and client creation

Just like with regular bevy_renet2, you need to create the RenetClient and NetcodeClientTransport or RenetServer and NetcodeServerTransport resources from Renet.

This crate will automatically manage their integration with Replicon.

Never insert client and server resources in the same app, it will cause a replication loop. See the Replicon’s quick start guide for more details.

The only Replicon-specific part is channels. You need to get them from the RepliconChannels resource. This crate provides the RenetChannelsExt extension trait to conveniently create renet channels from it:

use bevy::prelude::*;
use bevy_replicon::prelude::*;
use bevy_replicon_renet2::{renet2::ConnectionConfig, RenetChannelsExt};

fn init(channels: Res<RepliconChannels>) {
    let connection_config = ConnectionConfig::from_channels(
        channels.server_configs(),
        channels.client_configs(),
    );

    // Use this config for `RenetServer` or `RenetClient`
}

For a full example of how to initialize a server or client see examples in the repository.

Channels need to be obtained only after registering all replication components and remote events.

§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 client::*;client
pub use server::*;server
pub use common::*;

Modules§

clientclient
common
netcodenetcode
renet2
serverserver

Structs§

RepliconRenetPlugins