# 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 %}
