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

# Building Part

Defines a part in the scene with its own data, placement, behaviors, conditions and renderer settings. Manages renderer variants that allow visual switching without redefining existing settings.\
Presets allow configuration to be shared and reused across multiple Building Parts.

***

### How Parts Work

The [Building Part](/easy-build-system/reference/building-part.md) is the fundamental unit of the system. Every placeable object is a [Building Part](/easy-build-system/reference/building-part.md).\
It includes sub-systems for rendering, placement, conditions, behaviors, and caching.

Parts track their own state and publish events on every state change.\
They also support save/load callbacks for custom data persistence.

***

### Building States

**None**: Default. Part exists but isn't in any building action.

**Placed**: Part has been placed and is finalized.

**Queue**: Part is queued for construction (used by the [Survival Blueprint](/easy-build-system/extensions/survival-blueprint.md) extension).

**Placement**: Part is a preview being positioned.

**Adjusting**: Part is being moved to a new location.

**Destruction**: Part is marked for destruction.

***

### Sub-Systems

**Renderer System**: Manages visual variants, materials, bounds, and gizmos.

**Placement System**: Handles preview materials, movement, rotation, grid snapping, and state visuals.

**Behavior System**: Manages attached Building Behaviors. See the Building Behavior page.

**Condition System**: Manages attached Building Conditions. See the Building Condition page.

**Cache System**: Caches references to renderers, colliders, and rigidbodies.

***

### Scripting Examples

Check and change state:

```csharp
bool isPreview = part.IsPreview;  // true if Placement or Adjusting
bool isPlaced = part.IsPlaced;    // true if Placed
part.SetState(BuildingPart.BuildingState.Placed);
```

Socket attachment:

```csharp
part.SetSocket(socket);
part.ClearSocket();
BuildingSocket socket = part.AttachedSocket;
```

Group attachment:

```csharp
BuildingGroup group = part.AttachedGroup;
```

Move a part:

```csharp
part.Move(position, rotation, scale);
part.Move(snappingPoint, referenceTransform);
```

Save/load callbacks for custom data:

```csharp
part.SaveCallback += (stateData) =>
{
    stateData.SetInt("health", currentHealth);
};

part.LoadCallback += (stateData) =>
{
    currentHealth = stateData.GetInt("health");
};
```

Check if runtime-placed or pre-placed:

```csharp
bool wasPlacedAtRuntime = part.IsRuntimeInstantiated;
```

Listen for part events:

```csharp
EventPublisher.Subscribe<BuildingPartEvent.RegisteredEventArgs>(e =>
{
    Debug.Log("Part registered: " + e.Part.Name);
});

EventPublisher.Subscribe<BuildingPartEvent.StateChangedEventArgs>(e =>
{
    Debug.Log(e.Part.Name + " changed from " + e.LastState + " to " + e.NewState);
});

EventPublisher.Subscribe<BuildingPartEvent.ConditionFailedEventArgs>(e =>
{
    Debug.Log("Condition failed: " + e.Reason);
});

EventPublisher.Subscribe<BuildingPartEvent.PreviewCreatedEventArgs>(e =>
{
    Debug.Log("Preview created: " + e.Part.Name);
});
```

***

### Debug Visualization

The [Building Part](/easy-build-system/reference/building-part.md) draws a cyan wireframe cube showing its renderer bounds.\
If grid snapping is enabled, red grid cells show the snapping footprint.

Open the **Debug Settings** section on the component to access debug options.\
Displays the component's unique ID and registration state.

Use **Debug Draw Flags** to control where gizmos render: Scene View, Game View, or both.\
Gizmos can be toggled independently for the Renderer System and Placement System.


---

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