---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/delete
title: Delete messages
updated_at: 2026-05-25T11:25:51.108Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Delete messages

`Delete()` permanently removes a message from Message Persistence or marks it as `deleted` (soft delete).

:::note Requires Message Persistence
Enable [Message Persistence](https://youtu.be/qLMtbINWGig) and **Enable Delete-From-History** in the [Admin Portal](https://admin.pubnub.com/).
:::

### Method signature

This method takes the following parameters:

```csharp
message.Delete(bool soft = false)
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| soft | bool | Optional | `false` | Define if you want to permanently remove message data. By default, the message data gets permanently deleted from Message Persistence. If you set this parameter to `true`, the message's `IsDeleted` property is set to `true`, and you can still restore/get its data. |

#### Output

| Type | Description |
| --- | --- |
| `Task<ChatOperationResult>` | Returned `Task` that you can `await` to get the result of the delete operation. |

### Sample code

Permanently delete the message with the `16200000000000001` timetoken from the `support` channel.

```csharp
using System.Linq;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
        
// reference the "channel" object
var channelResult = await chat.GetChannel("support");
if (channelResult.Error)
{
    Debug.Log("Couldn't find channel!");
    return;
}
var channel = channelResult.Result;

// invoke the method on the "channel" object
var messagesResult = await channel.GetMessageHistory("16200000000000000", "16200000000000001", 1);
if (messagesResult.Error || !messagesResult.Result.Any())
{
    Debug.Log("Couldn't find message!");
    return;
}
var message = messagesResult.Result[0];

// permanently remove the message
await message.Delete(false);
```

### Other examples

Archive (soft delete) the message with the `16200000000000001` timetoken from the `support` channel, keeping its data in Message Persistence.

```csharp
using System.Linq;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
        
// reference the "channel" object
var channelResult = await chat.GetChannel("support");
if (channelResult.Error)
{
    Debug.Log("Couldn't find channel!");
    return;
}
var channel = channelResult.Result;

// invoke the method on the "channel" object
var messagesResult = await channel.GetMessageHistory("16200000000000000", "16200000000000001", 1);
if (messagesResult.Error || !messagesResult.Result.Any())
{
    Debug.Log("Couldn't find message!");
    return;
}
var message = messagesResult.Result[0];

// soft delete the message
await message.Delete(soft: true);
```