---
url: /api/kiln/variables/DespawnOnExit.md
---
[Kiln API](../../index.md) / [kiln](../index.md) / DespawnOnExit

# Variable: DespawnOnExit

```ts
const DespawnOnExit: Trait<{
  state: string;
  value: string;
}>;
```

Despawns the entity when its state is left: `commands.spawn(..., despawnOnExit(Screen, 'playing'))`.
`state` is the state's name, `value` the state value it belongs to.
