UnrealSharp
  • Home
  • FAQ
  • Getting Started
    • Setup
    • Your First Script
    • Debugging
    • Packaging
  • Documentation
    • Classes
      • Properties
        • C++ Functions As C# Properties
        • C++ Properties with Getters/Setters
      • Functions
        • Flags
        • MetaData
      • Default Actor Components
      • Helper Methods
    • Structs
    • Enums
    • Interfaces
    • Delegates
    • Collections
      • TArray
      • TNativeArray
      • TSet
      • TMap
    • Multiplayer
      • Replicated Properties
      • RPCs (Remote Procedure Calls)
      • Replicated UObjects
    • Primary Data Assets
      • Loading Primary Data Assets
    • Loading Soft References
    • Trace Channels
    • Static Variables
      • FWorldStaticVar<T>
      • FGameStaticVar<T>
    • Logging
    • Async
    • Gameplay Tags
      • Gameplay Tag Container
    • Extension / Mixin Methods
    • Subsystems
    • Module Lifecycle
  • Links
    • Github Repository
    • Roadmap
    • Discord
Powered by GitBook
On this page
  • Run on Server
  • Run on Owning Client
  • Multicast
  1. Documentation
  2. Multiplayer

RPCs (Remote Procedure Calls)

RPCs allow you to invoke functions across the network, enabling communication between the server and clients. These examples are parameterless, but of course they can contain parameters.

If you want a RPC to be unreliable, just don’t declare FunctionFlags.Reliable

Run on Server

Use the [UFunction] attribute with FunctionFlags.RunOnServer to indicate that a method should be executed on the server:

[UFunction(FunctionFlags.RunOnServer | FunctionFlags.Reliable)]
public void ServerFunction()
{
    // Server-side code
}

Run on Owning Client

Similarly, to execute a function on the owning client, use FunctionFlags.RunOnClient:

[UFunction(FunctionFlags.RunOnClient | FunctionFlags.Reliable)]
public void ClientFunction()
{
    // Client-side code
}

Multicast

For functions that should be executed on both the server and all clients, use FunctionFlags.Multicast:

[UFunction(FunctionFlags.Multicast | FunctionFlags.Reliable)]
public void MulticastFunction()
{
    // Code executed on both server and clients
}
PreviousReplicated PropertiesNextReplicated UObjects

Last updated 8 months ago