Index of every page on this site: llms.txt
All skills
jame581 avatar

/multiplayer-sync

@426e8ab
by Jan Mesarčjame581/godotprompter979 stars
63
Run it yourself

Use when synchronizing multiplayer state — MultiplayerSynchronizer, interpolation, prediction, and lag compensation

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/multiplayer-sync

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesbandwidth-optimization.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Bandwidth Optimization

Reference for skills/multiplayer-sync/SKILL.md — sync only changed properties, quantize floats, distance-based sync rate, reliable vs unreliable channel selection.

← Back to SKILL.md


7. Bandwidth Optimization

Sync Only Changed Properties

Set rarely-changing properties to On Change in the replication config: they are sent (reliably) only when they change, at most every delta_interval. Properties set to Always are sent every replication_interval whether they changed or not — a slower interval cuts their cost, but it does not resend the On Change properties.

func _ready() -> void:
    var sync := $MultiplayerSynchronizer
    sync.replication_interval = 0.1   # "Always" properties every 100 ms
    sync.delta_interval        = 0.05  # changed "On Change" properties every 50 ms
public override void _Ready()
{
    var sync = GetNode<MultiplayerSynchronizer>("MultiplayerSynchronizer");
    sync.ReplicationInterval = 0.1;  // "Always" properties every 100 ms
    sync.DeltaInterval       = 0.05; // changed "On Change" properties every 50 ms
}

Quantize Floats

Reduce float precision before sending. A 16-bit integer covers ±32767 cm — more than enough for most game worlds. RPC arguments and synced properties compress an int to 1, 2, 4 or 8 bytes plus a 1-byte type tag, so a value in the 16-bit range costs 3 bytes; a float is not compressed and costs 8 (12 if it is not exactly representable as a 32-bit float). Optionally, writing many values into one PackedByteArray (encode_s16()) also drops the per-value type byte, at the cost of the array's 8-byte header.

# Encode a position component to a 16-bit integer (1 cm precision, ±327 m range).
func quantize(value: float) -> int:
    return clampi(int(value * 100.0), -32768, 32767)

func dequantize(value: int) -> float:
    return float(value) / 100.0
// Encode a position component to a 16-bit integer (1 cm precision, +/-327 m range).
public static int Quantize(float value)
{
    return Mathf.Clamp((int)(value * 100.0f), -32768, 32767);
}

public static float Dequantize(int value)
{
    return value / 100.0f;
}

Distance-Based Sync Rate

Reduce the sync rate for objects far from the local player to save bandwidth.

# distance_sync_manager.gd — call from a timer or _physics_process
func update_sync_intervals(local_player: Node2D) -> void:
    for sync_node in get_tree().get_nodes_in_group("synced_objects"):
        var obj := sync_node.get_parent() as Node2D
        if obj == null:
            continue
        var dist: float = local_player.global_position.distance_to(obj.global_position)
        var multiplayer_sync := sync_node as MultiplayerSynchronizer
        if dist < 200.0:
            multiplayer_sync.replication_interval = 0.05   # 20 Hz — nearby
        elif dist < 600.0:
            multiplayer_sync.replication_interval = 0.1    # 10 Hz — medium
        else:
            multiplayer_sync.replication_interval = 0.5    # 2 Hz  — distant
// DistanceSyncManager.cs — call from a timer or _PhysicsProcess
public void UpdateSyncIntervals(Node2D localPlayer)
{
    foreach (Node syncNode in GetTree().GetNodesInGroup("synced_objects"))
    {
        if (syncNode.GetParent() is not Node2D obj)
            continue;
        float dist = localPlayer.GlobalPosition.DistanceTo(obj.GlobalPosition);
        var multiplayerSync = (MultiplayerSynchronizer)syncNode;
        if (dist < 200.0f)
            multiplayerSync.ReplicationInterval = 0.05;  // 20 Hz — nearby
        else if (dist < 600.0f)
            multiplayerSync.ReplicationInterval = 0.1;   // 10 Hz — medium
        else
            multiplayerSync.ReplicationInterval = 0.5;   // 2 Hz  — distant
    }
}

Reliable vs Unreliable Channels

Data Type Transfer mode Why
Position, velocity unreliable Timeliness matters; a dropped packet will be superseded by the next one
Health, score, kills reliable Must arrive and in order; gaps cause incorrect state
Spawn / despawn events reliable One-time events that must not be missed
Chat messages reliable Ordering and delivery matter to the user

In Godot, set the transfer mode per @rpc annotation (an optional trailing integer picks the channel):

@rpc("any_peer", "call_remote", "unreliable")
func update_position(pos: Vector2) -> void:
    synced_position = pos

@rpc("any_peer", "call_remote", "reliable")
func take_damage(amount: int) -> void:
    synced_health -= amount
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = false, TransferMode = MultiplayerPeer.TransferModeEnum.Unreliable)]
private void UpdatePosition(Vector2 pos)
{
    SyncedPosition = pos;
}

[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = false, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]
private void TakeDamage(int amount)
{
    SyncedHealth -= amount;
}

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts8d3 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    This skill provides documentation and code templates for implementing multiplayer synchronization in the Godot 4.3+ engine. It covers best practices for property replication, client-side prediction, and server-side validation. No security risks were identified.

  • Socket8d

    No alerts

  • Snyk8d

    Risk: LOW · No issues

Signed by skilld at 426e8ab. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated last month

README badge

README badge for jame581/godotprompter/multiplayer-sync