> For the complete documentation index, see [llms.txt](https://travljen.gitbook.io/unit-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://travljen.gitbook.io/unit-system/integration/unit-formation.md).

# Unit Formation

Guide on how to integrate formation behaviour with Unit System demo scripts

### Overview

This page is for guiding you through the process of basic integration for [**Unit Formation**](https://assetstore.unity.com/packages/tools/behavior-ai/unit-formation-210479) package. Refer to the [**Formation Guide**](https://travljen.gitbook.io/unit-formation) if you need more information.

### 1. Placement & Units

If you do not have **Unit Formation** package present, then follow it's guide for import and scene setup:

* Add **FormationPlacement** prefab in **scene**, configure it and its input
* You can skip `FormationUnit` component, but each unit still must have a script which implements `IFormationUnit`. You can do this by:

  * Updating your unit prefabs from using `NavMeshMovement` to `FormationNavMeshMovement` instead. It only extends functionality for the formation by implementing `IFormationUnit` interface. ***This way any update that happens to the formation position will cancel current active task that the units may have.***
  * Or if you are not using the provided movement scripts, make sure your movement script also implements `IFormationUnit` to receive a command to move unit to the new position in formation.

  <figure><img src="https://3582497942-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy2G6fDLEPuCAcuABMl6j%2Fuploads%2Fv2mncbULBZGiLiX5PYIT%2Fimage.png?alt=media&amp;token=3734ba41-a534-4763-94b9-7f00c025e8d3" alt=""><figcaption><p>FormationNavMeshMovement component</p></figcaption></figure>

### 2. Sync with Selection

In this step we need to sync selected units with formation package, so that formation placement may be used with all the selected units.&#x20;

* Add `SelectedUnitsFormation` component to your player, this will delegate any selection changes on `EntitySelectionManager` to the `FormationPlacement` component. This component also requires the **Player** reference, to make sure there are no unowned entities in the formation unit list.

Now you should already be able to use **Formation Placement** actions with the selected units.

### 3. Add to Player Interactions

This step adds formation capability to normal interactions for the selected units. When you are using provided demo scripts for interactions (`TargetedUnitInteractions` component) it already positions units in formation when there is no entity to interact with in that position. We now want to use the **Unit Formation** package to achieve this.

If you are not using provided interaction components, you can **skip this step**.

* Add **FormationPlacement** prefab from the **Unit Formation** package to your scene and configure it for your project.
* If you followed the [Set up Player](/unit-system/getting-started/creating-a-new-scene/set-up-player.md), find the for the **Player Interactions** object of your Player in the scene, and replace the `TargetedUnitInteractions` component on it with `TargetedFormationUnitInteractions`.&#x20;

  * This can be done by removing current component and replacing it with a new one, and then make sure all the references in scene are now pointing to the new component.
  * Another way to do it is to enable **Debug** view in **Inspector** and replace the script reference to the new class. And that's it.

  <figure><img src="https://3582497942-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy2G6fDLEPuCAcuABMl6j%2Fuploads%2FSU40txt5HFo8n96Z141X%2Fdebug%20view.gif?alt=media&amp;token=94451a60-9ddc-4f9f-8e0a-fb0720b312a1" alt=""><figcaption><p>Enter Debug view and replace class type</p></figcaption></figure>
