> 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/building-condition.md).

# Building Condition

Validates whether a building action is allowed or blocked on a [Building Part](/easy-build-system/reference/building-part.md).\
Each condition evaluates independently and returns a pass or fail result.

***

### How Conditions Work

Conditions are components attached to a [Building Part](/easy-build-system/reference/building-part.md).\
Every frame during preview, all conditions on the active part are evaluated in order.\
Each condition returns a `ConditionResult` with a valid/invalid flag and an optional reason string.\
The first failure blocks the action.

Conditions are cached per frame to avoid redundant evaluation.\
Each condition has an `EvaluationOrder` that determines the sequence. Lower values run first.

Conditions can be disabled without removing them, and debug logs can be enabled per condition to trace failures in the Console.

***

### Built-in Conditions

#### Common Condition (Required)

Controls allowed building modes and validates socket and area rules.

#### Collision Condition

Validates placement by detecting collisions, terrain contact, and overlapping [Building Parts](/easy-build-system/reference/building-part.md).\
Uses configurable bounds with independent collision checks per bound.\
Supports two evaluation modes: all bounds must pass, or at least one must pass.

#### Collapse Condition

Evaluates structural support and triggers a physics-based fall when the part becomes unstable. Configurable support detection via a bounds check on a layer mask.\
When unsupported, the part gets a Rigidbody and falls for a set time before cleanup.

#### Terrain Condition

Blocks placement on restricted terrain textures or near specific tree prototypes.\
Set denied texture indices with a weight threshold and denied tree prototypes with a detection radius.

***

### Creating Custom Conditions

Inherit from `BuildingCondition` and implement `EvaluateInternal`:

```csharp
using MindCodeInteractive.EasyBuildSystem.Framework.Code.Runtime.Systems.Controllers.States;
using MindCodeInteractive.EasyBuildSystem.Framework.Code.Runtime.Systems.Parts.Implementations.Conditions.Abstracts;
using MindCodeInteractive.EasyBuildSystem.Framework.Code.Runtime.Systems.Parts.Implementations.Conditions.Attributes;

[BuildingCondition("My Custom Condition", "Blocks placement during nighttime.")]
public class NightBlockCondition : BuildingCondition
{
    public override int EvaluationOrder => 10;

    protected override ConditionResult EvaluateInternal(BuildingMode buildMode)
    {
        if (buildMode != BuildingMode.Placement)
            return new ConditionResult(true);

        float hour = MyGameTime.CurrentHour;
        if (hour < 6f || hour > 20f)
            return new ConditionResult(false, "Cannot build at night.");

        return new ConditionResult(true);
    }
}
```

The `BuildingCondition` attribute defines the name and description shown in the inspector.

***

### Scripting Examples

Evaluate conditions manually:

```csharp
ConditionResult result = part.ConditionSystem.EvaluateConditions(BuildingMode.Placement);
if (!result.IsValid)
{
    Debug.Log("Blocked: " + result.Reason);
}
```

Listen for condition events:

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

EventPublisher.Subscribe<BuildingPartEvent.ConditionValidatedEventArgs>(e =>
{
    Debug.Log(e.Part.Name + " validated: " + e.IsValid);
});
```

***

### Debug Visualization

Each condition can draw its own gizmos.\
The Collision Condition draws wireframe cubes for its collision bounds.\
The Collapse Condition draws the support check volume beneath the part.

Open the **Debug Settings** section on each condition to access debug options.

Use **Debug Draw Flags** to control where gizmos render: Scene View, Game View, or both.


---

# 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/building-condition.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.
