CoherenceSync direct parent-child relationships
Objects with the
CoherenceSynccomponent can be connected to other objects with
CoherenceSynccomponents to form a parent-child relationship. For example, an object can be linked to a hand, a hand to an arm, and the arm to a spine.
When an object has a parent in the network hierarchy, its transform (position and orientation) will update in local space, which means its transform is relative to the parent's transform.
A child object will only be visible in a LiveQuery if its parent is within the query's boundaries.
Creating an Entity hierarchy is very simple. All you need to do is add a GameObject with a
CoherenceSynccomponent as a direct child of another GameObject with a
CoherenceSynccomponent. You can add and remove parent-child relationships at runtime (even from the editor).
Destruction or disconnection of the parent object will also destroy and remove all children of this object. Those objects' state needs to be treated on the Client side to be reinstantiated on the next connection.
Sometimes, it is not practical to add
CoherenceSyncobjects to all the links in the chain. For example, if a weapon is parented to a hand controlled by an Animator, we do not need to synchronize the entire skeleton over the network. In that case, see CoherenceNode.
If the child object is using LODs, it will base its distance calculations on the world position of its parent. For more details, see the Level of detail documentation.
When the parent
CoherenceSyncis destroyed, by default its
CoherenceSyncchildren get destroyed together with it. This can be changed via the Preserve Children option on the parent:\
When the Preserve Children option is enabled, destroying the parent entity will result in children getting unparented instead of being destroyed together with the parent. Those children will now reside at the root of the scene hierarchy.