# Entities: delete() method

> The delete() method of the Entities interface deletes an entity from the room.

The **`delete()`** method of the [`Entities`](/docs/room/entities) interface deletes an entity from the room. Clients that see it drop it in the next state update.

## Syntax

```ts
delete(entity)
```

### Parameters

`entity`
: The [`RoomEntity`](/docs/room/room-entity) to delete.

### Return value

None (`undefined`).

### Exceptions

`TypeError`
: Thrown if `entity` isn't an entity object.

## Description

Deleting an entity frees its key at once, and an explicit `id` can give its ID to a new entity. The entity is no longer returned by [`get()`](/docs/room/entities/get), [`all()`](/docs/room/entities/all) or [`ownedBy()`](/docs/room/entities/ownedby).

The object you hold still reads the values it had, but writing a field of it, or calling its `patch()`, throws an `Error`. Deleting an entity that's already deleted does nothing.

## Examples

### Removing a player's avatar when the player leaves

`onPlayerLeave` runs once the player's presence ends, so a dropped network that reconnects in time keeps the avatar.

```ts
// avatars.ts
import { defineRoom, defineSchema, entity } from "@irtio/room";

const Avatar = entity("avatar", { owner: "string", x: "f32", y: "f32" }, { key: "owner" });

export default defineRoom({
  schema: defineSchema({ entities: [Avatar] }),
  onJoin(room, connection) {
    if (!room.entities.get(Avatar, connection.player)) room.entities.create(Avatar, { owner: connection.player });
  },
  onPlayerLeave(room, player) {
    const avatar = room.entities.get(Avatar, player);
    if (avatar) room.entities.delete(avatar);
  },
});
```

## See also

- [`Entities.create()`](/docs/room/entities/create)
- [When the owner leaves](/docs/room/guides/ownership#when-the-owner-leaves), to delete owned entities without code
