menu_bookDocumentation

RPC Messages: Remote Procedure Calls with Broadcast, Owner, and Host Targets

calendar_today May 20, 2026 schedule ~1 min read person PatrickJr verified 50

Components can contain RPCs (Remote Procedure Calls). An RPC is a function that when called, is also called remotely on other clients.

Broadcast RPC

[Rpc.Broadcast] makes a function call broadcast to everyone:
CSHARP
void OnPressed()
{
    PlayOpenEffects();
}

[Rpc.Broadcast]
public void PlayOpenEffects()
{
    Sound.Play( "bing", WorldPosition );
}

Static RPC

Static methods can be RPCs without needing a Component:

CSHARP
[Rpc.Broadcast]
public static void PlaySoundAllClients( string soundName, Vector3 position )
{
    Sound.Play( soundName, position );
}

RPC Types

AttributeDescription
[Rpc.Broadcast]Calls the function for everybody
[Rpc.Owner]Only called for the owner of the networked object (or host if no owner)
[Rpc.Host]Only called on the host

NetFlags

CSHARP
[Rpc.Broadcast( NetFlags.Unreliable | NetFlags.OwnerOnly )]
public void PlayEffect( string sound, Vector3 pos ) { }
FlagDescription
NetFlags.UnreliableMay not arrive or arrive out of order. Fast and cheap. Good for effects.
NetFlags.ReliableDefault. Multiple attempts until received. Use for important events.
NetFlags.SendImmediateNot grouped with other messages, sent immediately. Good for streaming.
NetFlags.HostOnlyRPC can only be called from the host
NetFlags.OwnerOnlyRPC can only be called from the object's owner

Filtering Recipients

CSHARP
using ( Rpc.FilterExclude( c => c.DisplayName == "Harry" ) )
{
    PlayOpenEffects( "bing", WorldPosition );
}

using ( Rpc.FilterInclude( c => c.DisplayName == "Garry" ) )
{
    PlayOpenEffects( "bing", WorldPosition );
}

Caller Information

Check which connection called the RPC using Rpc.Caller:

CSHARP
[Rpc.Broadcast]
public void PlayOpenEffects( string soundName, Vector3 position )
{
    if ( !Rpc.Caller.IsHost ) return;
    Log.Info( $"{Rpc.Caller.DisplayName} ({Rpc.Caller.SteamId}) played effects" );
    Sound.Play( soundName, position );
}
Was this helpful?