BlockPlayerAsync
Available from 0.18.0. The reason argument is available from 0.19.2.
Logs that the local player blocked another player. UnblockPlayerAsync logs that they unblocked them.
Method Signatures
public async Task<ModerationEventResponse> BlockPlayerAsync(string targetUserId, string reason = null)
public async Task<PlaySafeApiResponse> UnblockPlayerAsync(string targetUserId, string reason = null)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
targetUserId | string | Yes | The unique ID of the player to block |
reason | string | No | Optional reason for the action. Defaults to null, in which case it is not sent |
The acting player is the local player, taken from your GetTelemetry delegate.
Returns
BlockPlayerAsyncreturns aModerationEventResponse, ornullif the request failed.UnblockPlayerAsyncreturns aPlaySafeApiResponse, ornullif the request failed.
Usage Example
var result = await PlaySafeManager.Instance.BlockPlayerAsync(targetPlayerId);
if (result != null && result.Ok)
{
Debug.Log($"Blocked {targetPlayerId}.");
}
else
{
Debug.LogWarning($"Could not block player: {result?.Message ?? "Unknown error"}");
}
// Later, to undo it
var undone = await PlaySafeManager.Instance.UnblockPlayerAsync(targetPlayerId);
Response Types
ModerationEventResponse
Data is a ModerationEvent:
public class ModerationEvent
{
public string Id { get; set; }
public string ProductId { get; set; }
public string ReporterPlayerUserId { get; set; }
public string ReporterRole { get; set; }
public string TargetPlayerUserId { get; set; }
public string EventType { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
PlaySafeApiResponse
public class PlaySafeApiResponse
{
public bool Ok { get; set; }
public object Data { get; set; }
public string Message { get; set; }
}
Error Handling
Both methods return null if the network request fails or the response cannot be parsed. Always check for null and verify Ok before proceeding.
Notes
- Blocks by other players count towards the target's respect score, the same as reports and mutes.
- Blocks appear in the player's stats as
numberOfBlocksByPlayer,numberOfBlocksByOtherPlayersandtotalBlocks. - Each player can have one
blockevent per target. CallingBlockPlayerAsyncagain for the same target does not create a second event; that call returns a response withOkset tofalse. - Undoing a block that was never made succeeds and changes nothing.
- These methods only record the action with PlaySafe. You still need to enforce the block in your own game (chat, voice, invites).