MutePlayerAsync
Available from 0.18.0. The reason argument is available from 0.19.2.
Logs that the local player muted another player. UnmutePlayerAsync logs that they unmuted them.
Method Signatures
public async Task<ModerationEventResponse> MutePlayerAsync(string targetUserId, string reason = null)
public async Task<PlaySafeApiResponse> UnmutePlayerAsync(string targetUserId, string reason = null)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
targetUserId | string | Yes | The unique ID of the player to mute |
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
MutePlayerAsyncreturns aModerationEventResponse, ornullif the request failed.UnmutePlayerAsyncreturns aPlaySafeApiResponse, ornullif the request failed.
Usage Example
var result = await PlaySafeManager.Instance.MutePlayerAsync(targetPlayerId);
if (result != null && result.Ok)
{
Debug.Log($"Muted {targetPlayerId}.");
}
else
{
Debug.LogWarning($"Could not mute player: {result?.Message ?? "Unknown error"}");
}
// Later, to undo it
var undone = await PlaySafeManager.Instance.UnmutePlayerAsync(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
- Mutes by other players count towards the target's respect score.
- Each player can have one
muteevent per target. CallingMutePlayerAsyncagain for the same target does not create a second event; that call returns a response withOkset tofalse. - Undoing a mute that was never made succeeds and changes nothing.
- These methods only record the action with PlaySafe. You still need to mute the player's audio in your own audio system.