# State Machines

In Unity, a **Finite State Machine (FSM)** can be used to manage movement and other behaviors of game characters or objects. FSM is a computational model that consists of a finite number of states, transitions, and actions. It works by transitioning from one state to another based on input or other conditions, performing specific actions associated with each state.

<figure><img src="/files/pyRhBqOhLPNCuYQdCbAR" alt=""><figcaption><p>Finite State Machine</p></figcaption></figure>

Instead of creating a single script that handles all movement or behavior for a game object, we can implement a more modular approach by breaking down states into smaller, individual scripts that implements Finite State Machine (FSM) methods. This approach leads to a cleaner and more maintainable solution, as it allows for easier addition and management of new or existing states.

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-type="rating" data-max="5"></th><th data-hidden data-type="rating" data-max="5"></th></tr></thead><tbody><tr><td>Adding Player States</td><td></td><td></td><td><a href="/files/WU7sHtRu0096u8BsUHwY">/files/WU7sHtRu0096u8BsUHwY</a></td><td><a href="/pages/gYuxXlRwIElQADOCxuDu">/pages/gYuxXlRwIElQADOCxuDu</a></td><td>null</td><td>null</td></tr><tr><td>Adding AI States</td><td></td><td></td><td><a href="/files/WU7sHtRu0096u8BsUHwY">/files/WU7sHtRu0096u8BsUHwY</a></td><td><a href="/pages/0QqMcTVzFlOzs7Q9ZAbu">/pages/0QqMcTVzFlOzs7Q9ZAbu</a></td><td>null</td><td>null</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.twgamesdev.com/uhfps/guides/state-machines.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
