> 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-manager.md).

# Building Manager

Registers and manages all [Building Parts](/easy-build-system/reference/building-part.md), [Sockets](/easy-build-system/reference/building-socket.md), [Areas](/easy-build-system/reference/building-area.md) and [Groups](/easy-build-system/reference/building-group.md) in the scene.\
Exposes a registry for querying registered components by type, ID or proximity.\
Handles the Grouping, Batching, Save, Grid, and Terrain sub-systems.

***

### How the Manager Works

The [Building Manager](/easy-build-system/reference/building-manager.md) is the singleton at the center of the system.\
Every building component registers itself here on initialization and unregisters on destruction.\
Provides the API for placing, destroying, adjusting, upgrading parts through the command system.\
It also hosts all sub-systems, each of which can be enabled or disabled independently.

The manager uses HashSet-based registries for fast lookups.\
It initializes sub-systems on `OnEnable` and shuts them down on `OnDisable`.\
The save system initializes on `Start` to ensure all scene objects are registered first.

***

### Sub-Systems

Each sub-system is configured in its own section on the [Building Manager](/easy-build-system/reference/building-manager.md) inspector:

**Grouping System**: Groups placed parts by proximity.

{% content-ref url="/pages/GjIEpvJW94o8s9xzybXW" %}
[Building Grid System](/easy-build-system/reference/building-manager/building-grid-system.md)
{% endcontent-ref %}

**Batching System**: Combines meshes within groups for fewer draw calls.

{% content-ref url="/pages/WmsmX5frgHSd4XsOMdLA" %}
[Building Grouping System](/easy-build-system/reference/building-manager/building-grouping-system.md)
{% endcontent-ref %}

**Save System**: Serializes and restores placed parts.

{% content-ref url="/pages/usAbbIR0cKRy8Ty4u5h8" %}
[Building Batching System](/easy-build-system/reference/building-manager/building-batching-system.md)
{% endcontent-ref %}

**Grid System**: Cell-based placement with visual rendering.

{% content-ref url="/pages/yGlv849yPb550ppbBNKX" %}
[Building Save System](/easy-build-system/reference/building-manager/building-save-system.md)
{% endcontent-ref %}

**Terrain System**: Backs up and restores terrain data.

{% content-ref url="/pages/0X6obn2vNXSrzuMwLuv8" %}
[Building Terrain System](/easy-build-system/reference/building-manager/building-terrain-system.md)
{% endcontent-ref %}

***

### Adding a Building Manager

1. Go to: `Tools > Mind Code Interactive > Easy Build System > Components > Create Building Manager...`
2. A [Building Manager](/easy-build-system/reference/building-manager.md) GameObject is added to the scene.
3. Configure sub-systems in the inspector as needed.

Only one [Building Manager](/easy-build-system/reference/building-manager.md) can exist per scene.

***

### Scripting Examples

Access the manager:

```csharp
BuildingManager manager = BuildingManager.Instance;
```

Query registered components:

```csharp
HashSet<BuildingPart> parts = BuildingManager.Instance.GetRegisteredParts;
HashSet<BuildingSocket> sockets = BuildingManager.Instance.GetRegisteredSockets;
HashSet<BuildingArea> areas = BuildingManager.Instance.GetRegisteredAreas;
HashSet<BuildingGroup> groups = BuildingManager.Instance.GetRegisteredGroups;
```

Find a part by ID:

```csharp
BuildingPart part = BuildingManager.Instance.GetPartByPrefabId("wall_01");
BuildingPart part = BuildingManager.Instance.GetPartByUniqueId(uniqueId);
```

Place a part via script:

```csharp
BuildingPart prefab = BuildingManager.Instance.GetPartByPrefabId("wall_01");
BuildingManager.Instance.PlacePart(prefab, position, rotation, scale);
```

Destroy a part:

```csharp
BuildingManager.Instance.DestroyPart(part);
BuildingManager.Instance.DestroyAllPlacedParts(includePreplaced: false);
```

Adjust and upgrade:

```csharp
BuildingManager.Instance.AdjustPart(part, newPosition, newRotation);
BuildingManager.Instance.UpgradePart(part, variantIndex);
```

Access sub-systems:

```csharp
BuildingManager.Instance.GroupingSystem;
BuildingManager.Instance.BatchingSystem;
BuildingManager.Instance.SaveSystem;
BuildingManager.Instance.GridSystem;
BuildingManager.Instance.TerrainSystem;
```

Set a network adapter:

```csharp
BuildingManager.SetNetworkAdapter(myNetworkAdapter);
BuildingManager.SetNetworkSaveAdapter(mySaveAdapter);
```


---

# 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-manager.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.
