# ConnectedEntity component

### Query

Objects with the `ConnectedEntity` component on them are treated in a special way by the query system. If the entity they are connected to is present in a query, then they are also included automatically. They are also excluded/removed automatically when the entity they are connected to goes out of the query.

{% hint style="info" %}
This means that the entity will never show up on its own – it will always have to be part of a query where the connected entity is included.
{% endhint %}

### Usage

You need to add the `ConnectedEntity` component to entity. The entity will disappear from all queries that don't have the entity this is connected to. The entity has to be converted to its `SerializeEntityID` before it can be used in the `ConnectedEntity` component. This can be done using the `CoherenceMonoBridge.UnityObjectToEntityId` static function.

```csharp
var entity = coherenceSync.LinkedEntity;

if(entity != Entity.Null)
{
    var serializeId = CoherenceMonoBridge.UnityObjectToEntityId(other)
    EntityManager.AddComponentData(entity, 
        new ConnectedEntity 
        { 
            Value = serializeId
        }
    );
}     
```

{% hint style="warning" %}
Please note that the *ConnectedEntity* component is only available in from code in ECS at the moment. It will be fully integrated with the editor flow in the next release.
{% endhint %}


---

# Agent Instructions: 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:

```
GET https://docs.coherence.io/0.4.14/connected-entities/connectedentity-component.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
