Not translated yet — showing English.
Cloud Functions & RPC
Keep the rules that matter on the server: the game asks, your server code decides. Server-side logic is a cloud function or a game server, deployed on its own. The game calls a cloud function with PlayServCode.CallAsync and gets a typed result; it calls a running game server with PlayServRpc.InvokeAsync.
using Playserv.Wrapper;
using UnityEngine;
var result = await PlayServCode.CallAsync<ClaimReward, RewardGranted>(
"claim-match-reward", new ClaimReward { MatchId = matchId });
if (result.IsSuccess)
Debug.Log($"+{result.Value.Coins} coins");
else
Debug.LogWarning(result.Error.SourceCode);
Choose a route
PlayServCode.CallAsync | PlayServRpc.InvokeAsync | |
|---|---|---|
| Reaches | A deployed cloud function | A cloud function or a game server, by name |
| Goes over | A request of its own | The connection the SDK keeps open |
| Use it for | Request and answer: claim a reward, buy an item, validate a move | Calls into your running game server |
| Versions | Can call a tagged version | No version choice |
For plain reads and writes of your own data, you don't need either: use records.
Call a cloud function
Deploy the function
Write the function and deploy it with the CLI, see Deploying with the CLI. Its slug, such as claim-match-reward, is the name the game calls.
Let the game call it
The execute setting in the function's manifest must allow calls from the client. If its auth requires a player, the game must be signed in. See Functions → Settings.
Call it
CallAsync<TRequest, TResponse>(slug, body) sends body as JSON and reads the answer as TResponse. CallAsync<TResponse>(slug) calls without a body.
Option (PlayServFunctionCallOptions) | What it does |
|---|---|
Version | Calls a tagged version instead of the latest. An unknown tag fails with function_version_not_found; there is no fallback to the latest. |
TimeoutSeconds | How long the game waits. The platform stops waiting for the function after 60 seconds, so a longer timeout changes nothing. |
Query · Headers | Query parameters and your own headers. |
StrictResponseTypes | Fails when the answer doesn't match TResponse, instead of filling what it can. |
CallAsync always sends a POST. For another method, or a raw body, use PlayServCode.InvokeAsync(new PlayServFunctionRequest { … }). InvokeBytesAsync and DownloadToFileAsync return binary answers; downloading to a file isn't available in WebGL.
Who is calling
The SDK sends the signed-in player's session with every call. The platform checks it and passes the player to your function, so the function knows who called. In a C# function it is Caller.PlayerId, with Caller.IsPlayer and Caller.IsAnonymous.
Never trust a player ID from the request body
Anyone can put any ID in the body. Take the player from the caller the platform passes, and check every value the game sends against your rules.
Call your game server (RPC)
using Playserv.RPC;
using Playserv.Wrapper;
PlayServRpcResult<RoundPreview> preview = await PlayServRpc.InvokeAsync<PreviewRequest, RoundPreview>(
"arena", "round.preview", new PreviewRequest { Round = 3 }); // sent as "Round": names must match the handler's parameters, case included
InvokeAsync(service, method, request) sends the call over the game's connection. The service name is the name of a deployed function or game server: PlayServ turns it into kebab-case and drops a trailing Service, so "Arena" and "ArenaService" both reach arena. The method name is passed to it.
| Detail | Value |
|---|---|
| Timeout | 30 seconds by default; set another with PlayServRpcInvokeOptions.Timeout. A cloud function reached by RPC must answer within 20 seconds. |
| Result | IsSuccess, Value and Error. Timeouts and failures come back in the result, not as exceptions: Error.Code is Timeout, ServerError and so on, and UnifiedError.SourceCode names the platform's reason. |
| Without waiting | PlayServRpc.Invoke(service, method, payload) sends the call and doesn't wait for the answer. |
| A game server with rooms | Only players taking part in one of its live rooms may call it. |
A Unity game server answers RPC with handlers registered in a PlayServServerRpcRegistry, see Game Server Hosting.
Function call errors and limits
For CallAsync, errors come back in result.Error; Error.SourceCode says what happened, and Error.Retryable whether trying again can help. Only bad arguments, a missing client key, and cancellation are thrown.
SourceCode | When |
|---|---|
not_found | No function with that slug in this project and environment. |
function_version_not_found | The Version tag doesn't exist. |
function_execute_forbidden | The function doesn't accept calls from the game. |
player_auth_required | The function needs a signed-in player. |
function_unreachable | The function didn't answer within 60 seconds, or is down. |
function_response_too_large | The answer is over 16 MiB. |
function_transport_failed | A network failure. Retryable. |
Any other status comes from your function itself, with its body in result.Response.
Make reward calls safe to repeat
A timeout doesn't mean the function didn't run: it may have finished after the game stopped waiting. For calls that grant something, pass an ID of the action, such as the match ID, and let the function ignore a second call with the same one.
Next steps
- Functions — deployed functions, their settings and version tags
- Deploying with the CLI — write and deploy a function
- Server Events — let your server tell players what happened
Last updated on 22 Oct 2026