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

# Building Socket

Defines a socket in the scene where [Building Parts](/easy-build-system/reference/building-part.md) can attach to each other.\
Each socket holds multiple snapping points with independent match rules per point.

***

### How Sockets Work

Sockets are child GameObjects on [Building Part](/easy-build-system/reference/building-part.md) prefabs.\
They define snap points where other parts can connect.\
During placement, the system searches for nearby sockets using physics overlap on the Socket layer. When a compatible socket is found, the preview snaps to the socket's offset position and rotation.

Each socket has a sphere trigger collider for detection.\
The collider radius matches the socket radius and is created automatically.\
Sockets track whether they're occupied by an attached part.

***

### Scripting Examples

Get all registered sockets:

```csharp
HashSet<BuildingSocket> sockets = BuildingManager.Instance.GetRegisteredSockets;
```

Find a socket by ID:

```csharp
BuildingSocket socket = BuildingSocket.GetSocketById(uniqueId);
```

Check if a socket is occupied:

```csharp
bool occupied = socket.HasAttachedPart();
BuildingPart attached = socket.AttachedPart;
```

Check if a socket fits a part:

```csharp
bool fits = socket.IsFitting(myPart);
```

Get the snap result for a part:

```csharp
SocketSnapResult result = socket.GetSnappingPoint(myPart);
if (result.IsValid)
{
    Debug.Log("Snap position: " + result.Position);
}
```

Listen for socket events:

```csharp
EventPublisher.Subscribe<BuildingSocketEvent.RegisteredEventArgs>(e =>
{
    Debug.Log("Socket registered: " + e.Socket.name);
});

EventPublisher.Subscribe<BuildingSocketEvent.UnregisteredEventArgs>(e =>
{
    Debug.Log("Socket unregistered: " + e.Socket.name);
});
```

***

### Debug Visualization

The [Building Socket](/easy-build-system/reference/building-socket.md) draws a wireframe sphere for detection radius, with arrows at snap points.

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.


---

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