---
url: /api/kiln/classes/Commands.md
---
[Kiln API](../../index.md) / [kiln](../index.md) / Commands

# Class: Commands

Deferred structural changes. They apply at the end of the current phase, in order.

## Constructors

### Constructor

```ts
new Commands(queue): Commands;
```

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `queue` | `CommandQueue` |

#### Returns

`Commands`

## Methods

### spawn()

#### Call Signature

```ts
spawn<P>(prefab, ...params): PendingEntity;
```

Queues a spawn from a prefab: `commands.spawn(Enemy, { at })`.

##### Type Parameters

| Type Parameter |
| ------ |
| `P` |

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `prefab` | [`Prefab`](../interfaces/Prefab.md)<`P`> |
| ...`params` | `P` *extends* `void` ? \[] : \[`P`] |

##### Returns

[`PendingEntity`](PendingEntity.md)

#### Call Signature

```ts
spawn(...traits): PendingEntity;
```

Queues a spawn from a trait list: `commands.spawn(Transform({ x: 1 }), Velocity)`.

##### Parameters

| Parameter | Type |
| ------ | ------ |
| ...`traits` | `ConfigurableTrait`\[] |

##### Returns

[`PendingEntity`](PendingEntity.md)

***

### despawn()

```ts
despawn(entity): void;
```

Queues a despawn. Despawning twice, or an entity that is already gone, is a no-op.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `entity` | [`EntityRef`](../type-aliases/EntityRef.md) |

#### Returns

`void`

***

### add()

```ts
add(entity, ...traits): void;
```

Queues adding traits (or relation pairs) to an entity.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `entity` | [`EntityRef`](../type-aliases/EntityRef.md) |
| ...`traits` | `ConfigurableTrait`\[] |

#### Returns

`void`

***

### remove()

```ts
remove(entity, ...traits): void;
```

Queues removing traits (or relation pairs) from an entity.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `entity` | [`EntityRef`](../type-aliases/EntityRef.md) |
| ...`traits` | (`Trait` | `RelationPair`)\[] |

#### Returns

`void`

***

### run()

```ts
run(fn): void;
```

Queues an arbitrary world mutation, applied in order with the others.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `fn` | (`world`) => `void` |

#### Returns

`void`
