> For the complete documentation index, see [llms.txt](https://mindcodeinteractive.gitbook.io/easy-build-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mindcodeinteractive.gitbook.io/easy-build-system/reference/building-controller.md).

# Building Controller

Manages the logic of building states, views and [Building Part](/easy-build-system/reference/building-part.md) selection.\
Dispatches input actions to the active building state.

***

### How the Controller Works

The [Building Controller](/easy-build-system/reference/building-controller.md) is the player-facing component that drives the building experience.\
It sits on your player or camera and coordinates the active mode, view, and part selection.\
On mode switch, the controller activates the corresponding state and routes input accordingly.\
The controller runs in `LateUpdate` so all other game logic executes before the building state updates.

The controller requires a `BuildingInput` component on the same GameObject.\
On `Reset`, it automatically creates all four [Building States](/easy-build-system/reference/building-controller/building-state.md) and a [First Person Building View](/easy-build-system/reference/building-controller/building-view.md).

***

### Building Modes

**None**: No active building mode. Normal gameplay.

**Placement**: Player is placing a new Building Part.

**Adjustment**: Player is moving an already-placed part.

**Destruction**: Player is removing an existing part.

**Upgrade**: Player is upgrading a part to a different variant.

***

### Adding a Building Controller

1. Add the `BuildingController` component to your player or camera.
2. A `BuildingInput` component is added automatically.
3. Assign one or more [Building Views](/easy-build-system/reference/building-controller/building-view.md) in the **Views** array.
4. Building States are created automatically on first setup.
5. The first view in the array becomes the active view.

***

### Scripting Examples

Switch building mode:

```csharp
BuildingController.Instance.SetMode(BuildingMode.Placement);
BuildingController.Instance.SetMode(BuildingMode.None); // exit
```

Select a part:

```csharp
BuildingPart wall = BuildingManager.Instance.GetPartByPrefabId("wall_01");
BuildingController.Instance.SelectPart(wall);
```

Switch camera view at runtime:

```csharp
BuildingController.Instance.SetView(BuildingViewType.ThirdPerson);
```

Trigger actions from script or UI buttons:

```csharp
BuildingController.Instance.ValidAction();
BuildingController.Instance.CancelAction();
BuildingController.Instance.RotateAction(1); // 1 or -1
```

Listen for controller events:

```csharp
EventPublisher.Subscribe<BuildingControllerEvent.BuildModeChangedEventArgs>(e =>
{
    Debug.Log("Mode changed to: " + e.Mode);
});

EventPublisher.Subscribe<BuildingControllerEvent.BuildSelectionChangedEventArgs>(e =>
{
    Debug.Log("Selected: " + e.SelectedPart.Name);
});

EventPublisher.Subscribe<BuildingControllerEvent.BuildViewChangedEventArgs>(e =>
{
    Debug.Log("View changed to: " + e.View);
});
```

Access current state:

```csharp
BuildingMode mode = BuildingController.Instance.ActiveMode;
BuildingPart selected = BuildingController.Instance.SelectedPart;
BuildingView view = BuildingController.Instance.ActiveView;
```

***

### UI Button Helpers

The controller exposes public methods for direct binding to Unity UI buttons:

```csharp
OnValidateButton()
OnCancelButton()
OnRotateButton(int direction)
OnEnterPlacementMode()
OnEnterDestructionMode()
OnEnterAdjustmentMode()
OnExitMode()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://mindcodeinteractive.gitbook.io/easy-build-system/reference/building-controller.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
