RPCs
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
FusionReplicatorchild → RPC is sent to that specific networked object on remote clients. - Broadcast RPC: The callable's object is
nullor has noFusionReplicator→ RPC is delivered to all registered broadcast receivers.
Object-Targeted RPCs
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
Global calls not tied to any object. Register a receiver, then call 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
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"checkshas_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
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.