# Entity references

Entity references let you set up references between entities and have those be synchronized, just like other value types (like integers, vectors, etc.)

To use Entity references, simply select any fields of type `GameObject`, `Transform`, or `CoherenceSync` for syncing in the Configuration window:

![](https://3580906557-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUrQ8GJkdHxImzMEWuxaz%2Fuploads%2Fgit-blob-b2125225a197ed8cad2969cf5736fa4945624589%2FScreenshot%202022-03-07%20at%2017.30.10.png?alt=media)

The synchronization works both when using reflection and in baked sync scripts.

Entity references can also be used as arguments in [Commands](https://docs.coherence.io/0.8/authority/commands).

### Limitations

It's important to know about the situations when an entity reference might become null, even though it seems like it should have a value:

* A client might not have the referenced entity in its live query. A local reference can only be valid if there's an actual entity instance to reference. If this becomes a problem, consider switching to using the [ConnectedEntity component](https://docs.coherence.io/0.8/connected-entities/parent-child) which ensures that another entity becomes part of the query.
* The owner of the entity reference might sync the reference to the Replication Server before syncing the referenced entity. This will lead to the Replication Server storing a null reference. If possible, try setting the entity references during gameplay when the referenced entities have already existed for a while.

In any case, it's important to use a defensive coding style when working with entity references. Make sure that your code can handle missing entities and nulls in a graceful way.


---

# 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.8/connected-entities/entity-references.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.
