# Unit.createState

Creates a Ai State from a name (See [AiState](../Game-Script-Environment/Userdata/AiState.md))

**Kind:** Function

**Environments:** Game

## Game

``` { .lua .api-signature }
unit:createState( stateName )
```

[Open the full Game reference](../Game-Script-Environment/Userdata/Unit.md#createstate)

**Availability:** Server only

**Parameters:**

| Name | Type | Description |
| --- | --- | --- |
| `unit` | [Unit](../Game-Script-Environment/Userdata/Unit.md) | The unit. |
| `stateName` | string | Name of predefined ai state. |

**Returns:**

| Type | Description |
| --- | --- |
| [AiState](../Game-Script-Environment/Userdata/AiState.md) | The ai state. |
