Skip to main content

Crate naia_bevy_client

Crate naia_bevy_client 

Source
Expand description

Bevy adapter for the naia client.

Integrates naia’s entity replication and messaging into a Bevy application. Server-replicated entities appear in the Bevy world automatically; client- authoritative entities can be spawned and published via CommandsExt.

Runs natively (UDP) and in the browser (wasm32-unknown-unknown + WebRTC).

§Single-client apps (most common)

Use DefaultPlugin and DefaultClientTag — no phantom type needed:

fn main() {
    App::new()
        // .add_plugins(DefaultPlugins)
        .add_plugins(DefaultPlugin::new(client_config(), protocol()))
        // .add_systems(Startup, init)  // call Client::connect here
        .run();
}

fn my_system(mut client: Client<DefaultClientTag>) {
    // use client here
}

§Multi-client apps

Disambiguate each server connection with a distinct phantom tag type:

struct LobbyTag;
struct GameTag;

fn main() {
    App::new()
        .add_plugins(Plugin::<LobbyTag>::new(lobby_config(), protocol()))
        .add_plugins(Plugin::<GameTag>::new(game_config(), protocol()))
        .run();
}

fn lobby_system(mut lobby: Client<LobbyTag>) { /* ... */ }
fn game_system(mut game: Client<GameTag>) { /* ... */ }

§Key types

TypePurpose
DefaultPluginSingle-client plugin (alias for Plugin<DefaultClientTag>)
PluginGeneric plugin for multi-client apps
ClientBevy-wrapped client SystemParam
DefaultClientTagPhantom type for single-client apps
CommandsExtExtension methods on Commands for replication
ClientCommandsExtClient-only extension methods on Commands
eventsBevy events mirroring naia world events

Modules§

default_channels
Built-in default channel definitions (DefaultUnreliable, DefaultReliable, etc.).
events
transport
Transport-layer socket abstractions (UDP, WebRTC, local in-process).

Structs§

Client
ClientConfig
Contains Config properties which will be used by a Server or Client
ClientWrapper
CommandHistory
Ring buffer of (tick, command) pairs for client-prediction rollback; old entries are pruned when the server acknowledges a tick.
DefaultClientTag
Phantom tag type for single-client Bevy apps.
GameInstant
Server-relative millisecond timestamp that wraps at 2^22 ms (~70 minutes).
HandleTickEvents
HandleWorldEvents
Instant
Represents a specific moment in time
Plugin
Bevy plugin that wires naia’s client replication into a Bevy App.
Random
Container for cross-platform Random methods
ResponseReceiveKey
Typed token held by the receiver to identify which request a response answers.
ResponseSendKey
Typed token held by the sender to identify a pending request when its response arrives.
ServerOwned
Timer
A Timer with a given duration after which it will enter into a “Ringing” state. The Timer can be reset at an given time, or manually set to start “Ringing” again.
WorldUpdate

Enums§

EntityAuthStatus
Authority lifecycle state for a delegated entity as observed by one endpoint.
JitterBufferType
Configuration type for jitter buffer behavior
NaiaClientError
Errors that can be returned by the naia client.
Publicity
Publication visibility of an entity — the shared axis used on both sides of the connection.

Traits§

AppRegisterComponentEvents
ClientCommandsExt
Extension methods on Commands for client-side replicated resource authority management.
CommandsExt
Extension methods on EntityCommands for client-side replication and authority management.
Message
Core trait for all naia message types — provides serialization, kind lookup, and entity-relation hooks.
Replicate
A struct that implements Replicate is a Component, or otherwise, a container of Properties that can be scoped, tracked, and synced, with a remote host
ReplicateBundle

Functions§

sequence_greater_than
Returns whether or not a wrapping number is greater than another sequence_greater_than(2,1) will return true sequence_greater_than(1,2) will return false sequence_greater_than(1,1) will return false
sequence_less_than
Returns whether or not a wrapping number is greater than another sequence_less_than(1,2) will return true sequence_less_than(2,1) will return false sequence_less_than(1,1) will return false
wrapping_diff
Retrieves the wrapping difference between 2 u16 values wrapping_diff(1,2) will return 1 wrapping_diff(2,1) will return -1 wrapping_diff(65535,0) will return 1 wrapping_diff(0,65535) will return -1

Type Aliases§

ClientOwned
DefaultPlugin
Alias for Plugin<DefaultClientTag> — for single-client apps.
Tick
Server-side tick counter, wrapping at u16::MAX.

Derive Macros§

Message
Derives the Message trait for a given struct
Replicate
Derives the Replicate trait for a given struct, for the Bevy adapter. Users add their own #[derive(Component)] alongside this derive, so we skip auto-emitting a Bevy Component impl here.