🐾PurrNet Docs
RPC

TargetRpc

TargetRpc sends a method call from the server to a single specific client. Use it for private messages, personal UI updates, or per-player results that other clients must not see.

Client AServerClient BServer → Single target client

How it works

The server calls a method marked with [TargetRpc], passing a PlayerID as the first argument. Only that player's client executes the method body. All other connected clients are unaware of the call.

Common uses: displaying private chat messages, delivering loot drops to an inventory, sending kill confirmations, or sharing per-player secret game data.

Parameters

ParameterTypeDefaultDescription
target (first argument)reqPlayerID—The PlayerID of the client to receive this call. Pass null to send to the object's current owner. Passed as the first argument in the method signature.
requireServerboolNetwork RulesWhen true, only the server can call this RPC.
bufferLastboolfalseStores the most recent call and replays it to the target player when they join.
runLocallyboolfalseThe caller also executes the method immediately.

Basic usage

QuestSystem.cs
using PurrNet;

public class QuestSystem : NetworkBehaviour
{
    // Only the specific player receives their quest reward
    [TargetRpc]
    public void RpcGrantReward(PlayerID target, int goldAmount, string itemName)
    {
        // Runs ONLY on the client matching 'target'
        UI.ShowRewardPopup(goldAmount, itemName);
        AudioManager.Play("reward_fanfare");
    }

    // Server trigger — after quest completion check
    [ServerRpc(requireOwnership: false)]
    public void CmdCompleteQuest(int questId, RPCInfo info = default)
    {
        if (!ValidateQuestCompletion(info.sender, questId)) return;

        var reward = questDatabase.GetReward(questId);
        // Send reward only to the completing player
        RpcGrantReward(info.sender, reward.gold, reward.item);
    }
}
TargetRpc is the right choice for any data that should stay private to one player — inventory loot, personal notifications, anti-cheat feedback, or spectator-only information.