Why is the LinkedEntityGroup component added when instanting entities?

I’m generating entities with the EntityManager.Instantiate method using an entity prefab. When I inspect the archetype I see the LinkedEntityGroup component (see the attachment please). It’s the largest in size. Why is it there? What is the usage of this?

LinkedEntityGroup is used both during instantiation to create all linked entities, but also when you destroy an entity so it can destroy all it’s linked entities as well.

But there is no linked entity. It’s just this one. And the value of the LinkedEntityGroup item is the entity itself. I’m sending the image of the component value. Check it out, please.

8034326--1035986--arc2.png

1 Like

“The LinkedEntityGroup buffer makes the entity be the root of a set of connected entities. Referenced Prefabs automatically add a LinkedEntityGroup with the complete child hierarchy. EntityManager.Instantiate uses LinkedEntityGroup to instantiate the whole set of entities automatically. EntityManager.SetEnabled uses LinkedEntityGroup to enable the whole set of entities”
https://docs.unity3d.com/Packages/com.unity.entities@0.0/api/Unity.Entities.LinkedEntityGroup.html

Yeah I see what you’re saying. It does seem a bit unneeded to had the buffer if you have no children or linked entities.

having a look at source, you couldn’t even run a post conversion cleanup system in GameObjectAfterConversionGroup because adding LinkedEntityGroups occurs last

                   conversion.MappingSystem.CreatePrimaryEntities();

                    conversionWorld.GetExistingSystem<GameObjectBeforeConversionGroup>().Update();
                    conversionWorld.GetExistingSystem<GameObjectConversionGroup>().Update();
                    conversionWorld.GetExistingSystem<GameObjectAfterConversionGroup>().Update();
                }

                using (s_AddPrefabComponentDataTag.Auto())
                    conversion.MappingSystem.AddPrefabComponentDataTag();

#if !UNITY_DISABLE_MANAGED_COMPONENTS
                using (s_CreateCompanionGameObjects.Auto())
                    conversion.MappingSystem.CreateCompanionGameObjects();
#endif

                using (s_GenerateLinkedEntityGroups.Auto())
                    conversion.MappingSystem.GenerateLinkedEntityGroups();

Sorry but I don’t understand. I just created a simple prefab and generate an entity with it. There is no hierarchy. If you look at the attached image of the component value, you can see that the value is the same as the entity.

Is it adding itself by default? If so, why?

That’s bad. And I don’t understand why the size of it too big. Isn’t it just a reference value?

For performance by default buffers allocate into the chunk. Only once the buffer exceeds it’s max chunk capacity is it moved out.

This is defined by
InternalBufferCapacityAttribute

Where
public const int DefaultBufferCapacityNumerator = 128;

So as LinkedEntityGroup does not assign a InternalBufferCapacity it allocates a size of 128.
The remaining 16 come from the actual buffer data (m_InternalCapacity etc).

So yeah by default, all buffers have a size of 144 but if you add a InternalBufferCapacity[0] to your IBufferElement then it should only be 16 in your chunk.

Such a waste… I removed the LinkedEntityGroup component after intantiating the entity. Hope it won’t cause any problems.

Why not just remove the buffer if you don’t need it?

Well I just did that and edited my comment at the same time you post this :slight_smile:

1 Like

LinkedEntityGroup requires the first element as the root parent. It must have added itself automatically when the LinkedEntityGroup elements are created even when there are no child entities to add.