🐾PurrNet Docs
Sync Type

SyncInput

SyncInput<T> synchronises raw player input from the owning client to the server using an unreliable fast path, giving the server the freshest possible input with minimal bandwidth.

SyncInput — owner → server, every ticktick #40
Owner (Client A)
↑
←
↓
→
Jump
InputState sampled each tick
▶
Server
authoritative processing
Other clients:
Client B× not involved
Client C× not involved
Input never reaches peers

Why SyncInput exists

The conventional approach for server-authoritative movement is to send a [ServerRpc] every frame. This works, but reliable RPCs add round-trip latency and the ordered delivery guarantee wastes bandwidth for data where only the latest value matters. SyncInput<T> is purpose-built for this case: it uses an unreliable channel, discards out-of-order packets automatically, and sends the freshest input each tick — giving the server the lowest-latency view of what the player is doing without the overhead of a full RPC.

Properties

ParameterTypeDefaultDescription
valueT—The current input value. Only the owning client should write to this. All other machines read it.
onChangedevent Action<T>—Fires on the server (and other clients if configured) whenever a new input value arrives from the owner.
ownerAuthbooltrueAlways true for SyncInput — only the owner can write input. This is not configurable; it is the defining feature of SyncInput.

Basic usage

Declare a SyncInput<T> field on your NetworkBehaviour. The owner writes .value every frame; the server reads the latest value via onChanged or by polling .value directly.

TopDownMovement.cs
using PurrNet;
using UnityEngine;

[RequireComponent(typeof(Rigidbody2D))]
public class TopDownMovement : NetworkBehaviour
{
    [SerializeField] private float moveSpeed = 6f;

    // Owner writes each frame; server reads and applies physics
    private SyncInput<Vector2> _moveInput = new();
    private SyncInput<bool>    _sprintInput = new();

    private Rigidbody2D _rb;

    private void Awake()
    {
        _rb = GetComponent<Rigidbody2D>();

        // Server subscribes to react to incoming input
        if (isServer)
            _moveInput.onChanged += OnMoveInputReceived;
    }

    private void Update()
    {
        // Only the owner reads local input and writes to SyncInput
        if (!isOwner) return;

        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");

        _moveInput.value   = new Vector2(h, v).normalized;
        _sprintInput.value = Input.GetKey(KeyCode.LeftShift);
    }

    private void OnMoveInputReceived(Vector2 input)
    {
        // Server-side: apply physics from the received input
        float speed = _sprintInput.value ? moveSpeed * 1.8f : moveSpeed;
        _rb.linearVelocity = input * speed;
    }

    private void FixedUpdate()
    {
        // Alternative: poll each physics tick instead of using onChanged
        if (!isServer) return;
        float speed = _sprintInput.value ? moveSpeed * 1.8f : moveSpeed;
        _rb.linearVelocity = _moveInput.value * speed;
    }
}

Situational example — aim direction for a twin-stick shooter

In a top-down twin-stick shooter, the aim direction changes every frame based on the right thumbstick or mouse position. Sending this as a reliable RPC would be wasteful — if a packet drops the next one makes it irrelevant anyway.

PlayerAiming.cs
using PurrNet;
using UnityEngine;

public class PlayerAiming : NetworkBehaviour
{
    [SerializeField] private Transform turretPivot;

    // Continuous aim direction synced from owner → server
    private SyncInput<float> _aimAngle = new(); // angle in degrees

    private void Awake()
    {
        // Server reads aim angle to validate hit detection
        if (isServer)
            _aimAngle.onChanged += OnAimChanged;
    }

    private void Update()
    {
        if (isOwner)
        {
            // Mouse aim
            Vector3 mouseWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 dir = (mouseWorld - transform.position).normalized;
            float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
            _aimAngle.value = angle;
        }

        // All clients can read the synced value to rotate the visual
        turretPivot.rotation = Quaternion.Euler(0, 0, _aimAngle.value);
    }

    private void OnAimChanged(float angle)
    {
        // Server updates its authoritative aim state for hit-scan validation
        ServerAimRegistry.UpdateAim(owner, angle);
    }

    [ServerRpc(requireOwnership: true)]
    public void CmdFireWeapon()
    {
        // Server already has the latest aim angle from SyncInput
        float angle = _aimAngle.value;
        Vector2 dir = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad));

        var hit = Physics2D.Raycast(transform.position, dir, 50f);
        if (hit.collider && hit.collider.TryGetComponent<PlayerHealth>(out var health))
            health.CmdTakeDamage(25);
    }
}

SyncInput vs ServerRpc for input

ParameterTypeDefaultDescription
SyncInput<T>unreliable channel—Dedicated input sync path. Uses an unreliable channel for minimum latency. Newest value wins — old packets are discarded. Best for continuous analog input (movement, aim).
ServerRpc (Reliable)reliable channel—Every call is guaranteed to arrive in order. Adds round-trip latency plus retransmission overhead. Best for discrete commands (jump, fire, interact) where missing a packet matters.
ServerRpc (Unreliable)unreliable channel—Low latency but may drop packets. No built-in "latest wins" semantics — dropped packets cause gaps. SyncInput handles sequencing automatically, making it the better choice for continuous input.

SyncInput uses an unreliable channel by default

Packets sent via SyncInput may arrive out of order or not at all. PurrNet automatically discards any packet whose sequence number is older than the last-received value, so .value always reflects the most recent input the server has seen. This is ideal for analog axes but unsuitable for discrete commands like jumping or firing — use a reliable [ServerRpc] for those.

Combine SyncInput with ServerRpc for mixed schemes

A common pattern is to use SyncInput<Vector2> for continuous movement and aim, and separate [ServerRpc] calls for discrete actions like jumping, dashing, or using an ability. This gives you low-latency input for analogue axes while guaranteeing delivery for one-shot commands.