Best Practices for Child Entity Relationships? (ECS)

In GameObjects I have a prefab with child objects; such as a car, with a replaceable spoiler. The spoiler always renders in the same local position compared to the parent car model.

In ECS, when I place this prefab in a subscene, the child entities (Spoiler, Rims, etc.) don’t move with the parent entity (car). Per the usual approach to ECS, I found several tutorials and examples that no longer work in ECS now (Unity 6, ECS 1.3.5) about parenting, SharedData, LocalTransform.

I don’t want to just hack the approach. I’m looking for recommendations to parent objects in ECS, or recommendations on restructuring prefabs to work better for ECS.

Here are some assumptions I have now.

  • It is better, when possible, to fully combine meshes/materials into a single mesh/material, so multiple entities don’t need to work together.
  • Parenting can be expensive.
  • It would be more efficient to generate a custom structure/component that contains the multiple meshes and materials needed to render a car, but I would also have to create a custom system to reproduce the draw calls.
  • I’m NOT diving into children with separate physics or colliders in this consideration, like wheels.
  1. Can anyone recommend videos, tutorials or articles that address how to think through this?
  2. Are there any specific recommendations or considerations to share on this?
  • Thanks!

You need to add the LinkedEntityGroupAuthoring to the parent, then the children will follow it.

One thing I found with ECS is to try to reduce parent/child relationships as much as possible so that the LocalToWorldSystem doesn’t start taking too much time. This video shows why https://www.youtube.com/watch?v=O6QR9l-vQpY&t=2s

If you are willing to explore beyond what Unity has to offer, you can break past those assumptions and really push the limits of what you can achieve.

Regarding the expensiveness of transforms and parenting: Latios-Framework-Documentation/Optimization Adventures/Part 9 - Transform Hierarchy 1.md at main · Dreaming381/Latios-Framework-Documentation · GitHub

And regarding mesh and material combining, there’s this for background: Latios-Framework-Documentation/Optimization Adventures/Part 13 - LODS 1.md at main · Dreaming381/Latios-Framework-Documentation · GitHub
And this for how it can be extended to multiple meshes and materials: Latios-Framework-Documentation/Optimization Adventures/Part 14 - Operation Reduction 1.md at main · Dreaming381/Latios-Framework-Documentation · GitHub

But in practice, if you don’t have performance problems with Unity’s ECS transform system or rendering, you are probably better off not worrying about these optimizations.

1 Like