RPCs

Replication handles continuous state - properties that change over time like position, health or score. But games also need one-shot events: a player fires a weapon, sends a chat message or triggers an ability. Remote Procedure Calls (RPCs) fill this gap by letting one client invoke a function on other clients without storing anything in the sync buffer.

RPCs are fire-and-forget - they are delivered once and not retained. If a client joins after an RPC was sent, it will not receive that call. For state that must survive late joins, use replicated properties instead.

Overview

Fusion RPCs are sent through the FusionClient singleton. Routing is automatic - if the callable belongs to a node with a FusionReplicator child, it's an object-targeted RPC; otherwise it's a broadcast RPC.

All RPC methods live on FusionClient. Annotate receiving functions with @rpc as usual.

Three Calling Styles

rpc() - Send to All

GDScript

FusionClient.rpc(my_method, arg1, arg2)

Sends to every peer (equivalent to rpc_to(FusionClient.TARGET_ALL, ...)).

rpc_to() - Send to Enum Target

GDScript

FusionClient.rpc_to(FusionClient.TARGET_MASTER, my_method, arg1)
FusionClient.rpc_to(FusionClient.TARGET_OWNER, my_method, arg1)   # object RPCs only
FusionClient.rpc_to(FusionClient.TARGET_PLUGIN, my_method, arg1)

First argument is a FusionClient.RpcTarget enum value.

rpc_to_player() - Send to Specific Player

GDScript

FusionClient.rpc_to_player(player_id, my_method, arg1, arg2)

Targets a specific player by their numeric ID (must be > 0).

RpcTarget Enum

All constants are on FusionClient:

Constant Description
TARGET_ALL All peers (default)
TARGET_MASTER Master client only
TARGET_PLUGIN Server plugin only (custom Photon plugin)
TARGET_OWNER Object owner only - object RPCs only, errors on broadcast

Object vs Broadcast Routing

Routing is determined automatically by the callable:

  • Object RPC: The callable's object has a FusionReplicator child → RPC is sent to that specific networked object on remote clients.
  • Broadcast RPC: The callable's object is null or has no FusionReplicator → RPC is delivered to all registered broadcast receivers.

Object-Targeted RPCs

Object-targeted RPCs invoke a method on a specific networked object across clients. The callable must belong to a node that has a FusionReplicator child.

GDScript

@rpc("any_peer", "call_local")
func take_damage(amount: int):
    health -= amount

func attack():
    # Callable bound to this node → routes through our FusionReplicator
    FusionClient.rpc(take_damage, 10)

    # Send only to owner
    FusionClient.rpc_to(FusionClient.TARGET_OWNER, take_damage, 10)

Broadcast RPCs

Broadcast RPCs deliver a message to all clients without targeting a specific networked object. Register a receiver node, then send via FusionClient.

GDScript

func _ready():
    FusionClient.register_broadcast_receiver(self)

func _exit_tree():
    if FusionClient:
        FusionClient.unregister_broadcast_receiver(self)

@rpc("any_peer", "call_local")
func chat_message(sender: String, text: String):
    print("[%s]: %s" % [sender, text])

func send_chat(text: String):
    FusionClient.rpc(chat_message, sender, text)

Always unregister broadcast receivers in _exit_tree() to prevent crashes.

@rpc Annotation

Godot's @rpc annotation configures who is allowed to send and whether the call also executes locally on the sender.

GDScript

@rpc("any_peer", "call_local")    # Any peer can send, also executes locally
@rpc("authority")                  # Only authority can send (default)
@rpc("any_peer", "call_remote")   # Any peer, remotes only
  • Mode: "authority" checks has_authority() before sending. "any_peer" allows anyone.
  • Sync: "call_remote" (default) sends to remotes only. "call_local" also executes on the sender immediately after sending.

Supported Argument Types

Fusion RPCs support most Godot built-in types plus networked Node references.

bool, int, float, String, Vector2, Vector3, Vector4, Quaternion, Color, PackedByteArray, Array, Dictionary, and networked Node references (encoded as Fusion ObjectId).

Node references may be null on the receiving end if the object was despawned before the RPC arrived.

Back to top