#Stop LinkedEntityGroup from being added to prefabs

1 messages · Page 1 of 1 (latest)

onyx eagle
#

In pre.65 this behaviour doesn't exist. But after upgrading to 1.0.10, LinkedEntityGroup is being added to every prefabs regardless they have children or not. I don't want this. I only want LinkedEntityGroup on entities that have children. How to stop this behaviour for a prefab that just consists of 1 entity and no children?

bold laurel
#

(That said I don't think this behaviour changed recently, it's existed since 1.0 was first released. I wrote this back in dec 2022 to solve the problem)

onyx eagle
#

Hmm, because I remember that I didn't see it on my prefabs until today.

#

I only know about this because my DestroyEntitySystem complains about LinkedEntityGroup isnt included in the query.

#

But this system run fine just before today

bold laurel
#

🤷‍♂️ nothing has changed with the code

#

if you want to edit in the actual entities package

#

change

#
internal Entity CreateEntityForPrefab(GameObject prefab)
{
    var instanceId = prefab.GetInstanceID();
    var entity = CreateEntityForGameObject(prefab, 0, _DefaultArchetypePrefab, 0);
    _GameObjectToEntity[instanceId] = entity;

    // Make sure prefab root is dynamic
    var counters = new TransformUsageFlagCounters();
    counters.Add(TransformUsageFlags.Dynamic);
    _ReferencedEntities.Add(entity, counters);

    // Now register the Prefab for lazy baking
    _AdditionalGameObjectsToBake.Add(instanceId);

    // Add all children
    var allTransforms = prefab.GetComponentsInChildren<Transform>(true);
    var linkedEntityGroupArray = new NativeArray<LinkedEntityGroupBakingData>(allTransforms.Length, Allocator.Temp);

    // Assign self to first position in linked entity group
    linkedEntityGroupArray[0] = new LinkedEntityGroupBakingData {Value = entity};

    for(int i = 1; i < allTransforms.Length; i++)
    {
        var childGameObject = allTransforms[i].gameObject;
        var childEntity = CreateEntityForGameObject(childGameObject, 0, _DefaultArchetypePrefab, 0);

        _GameObjectToEntity[childGameObject.GetInstanceID()] = childEntity;

        linkedEntityGroupArray[i] = new LinkedEntityGroupBakingData {Value = childEntity};
    }

    var buffer = _EntityManager.AddBuffer<LinkedEntityGroupBakingData>(entity);
    buffer.AddRange(linkedEntityGroupArray);
    linkedEntityGroupArray.Dispose();

    return entity;
}```
#

into

#
internal Entity CreateEntityForPrefab(GameObject prefab)
{
    var instanceId = prefab.GetInstanceID();
    var entity = CreateEntityForGameObject(prefab, 0, _DefaultArchetypePrefab, 0);
    _GameObjectToEntity[instanceId] = entity;

    // Make sure prefab root is dynamic
    var counters = new TransformUsageFlagCounters();
    counters.Add(TransformUsageFlags.Dynamic);
    _ReferencedEntities.Add(entity, counters);

    // Now register the Prefab for lazy baking
    _AdditionalGameObjectsToBake.Add(instanceId);

    // Add all children
    var allTransforms = prefab.GetComponentsInChildren<Transform>(true);
    if (allTransforms.Length > 1)
    {
        var linkedEntityGroupArray = new NativeArray<LinkedEntityGroupBakingData>(allTransforms.Length, Allocator.Temp);

        // Assign self to first position in linked entity group
        linkedEntityGroupArray[0] = new LinkedEntityGroupBakingData {Value = entity};

        for(int i = 1; i < allTransforms.Length; i++)
        {
            var childGameObject = allTransforms[i].gameObject;
            var childEntity = CreateEntityForGameObject(childGameObject, 0, _DefaultArchetypePrefab, 0);

            _GameObjectToEntity[childGameObject.GetInstanceID()] = childEntity;

            linkedEntityGroupArray[i] = new LinkedEntityGroupBakingData {Value = childEntity};
        }

        var buffer = _EntityManager.AddBuffer<LinkedEntityGroupBakingData>(entity);
        buffer.AddRange(linkedEntityGroupArray);
        linkedEntityGroupArray.Dispose();
    }

    return entity;
}```
#

but i personally prefer not to fork the entities package

onyx eagle
#

Well thanks, I'm just expressing my confusion.

bold laurel
#

hence i just use my post processing baking system

onyx eagle
#

I will go with the post processing

#

I don't want to mess with the package too

bold laurel
#

but yeah, it's deliberate added but i strongly disagree with it

jolly breach
#

I can confirm, this behavior has been this way for a while (at least since early pre-releases).

onyx eagle
#

However the problem is still the same. LinkedEntityGroup takes a lot of space because there is no [InternalBufferCapacity(0)] defined.

#

Also it prevents entities from being destroyed by a query if it don't include the component.