Hierarhy is broken when instantiating Entitity from entity prefab and one of the childs is disabled

Entitites 0.11

I have the following prefab structure

– Root
---- Child 1
---- Child 2 // Disabled

Prefab was converted by subscene.

When I am instantiating it using EntityCommandBuffer.Instantiate the second child is missing from Child buffer in Root entitiy.
If I disable Root on prefab, the Child buffer is completely missing on Root entity.

Childs is missing even if I remove Disabled component from it.

Is this somehow intended behaviour?

1 Like

Also EntityCommandBuffer.SetEnabled(entity, bool) would be very usefull

Posted about the issue here as well:

Looking through the conversion world source code, it looks like referenced prefabs are never checked for ‘Covert’ or ‘StopConvert’ components. It’s just assumed everything in the prefab hierarchy should be converted to an entity.

My best guess was that when the StopConvert component was implemented (which was a later addition to the conversion ecosystem) that prefab support was innocently missed.

I’m using an uncomfortable workaround for this, in which I use a Conversion System to catch prefab children which should be disabled, and destroy their entities with EntityManager. I would love to not need to do this.

Ah, my apologies - it looks like we are talking about two different bugs (disabled entities, vs StopConvert MonoBehaviours).

Didn’t mean to hijack the topic. GL.

Also PreviousParent value is Entity.Null in this case.

I can confirm this is an issue. What happens is after any hierarchical change, the transform system reacts to the changes and cleans up using change filtering. However, if the entities are disabled when the transform system runs, the transform system does not apply the necessary changes. Then by the time the entities are enabled, the parent component has not been touched for several transform system updates and the change filter ignores them. Why that happens in spite of the structural changes that should be made when enabling the entities requires way too much digging into the code for me to be bothered with right now.

The workaround is to dirty the Parent components on each child after enabling by reading the Parent value and then setting it to the same value. You can do this in a job using ComponentDataFromEntity.

//Todo: It seems that if you Instantiate and then immediately disable a Transform hierarchy, the disabled entities do not get their child buffers.
            //This hack attempts to dirty the children so that the transform system picks up on this.
            var linkedBfe  = GetBufferFromEntity<LinkedEntityGroup>(true);
            var parentCdfe = GetComponentDataFromEntity<Parent>(false);
            Job.WithCode(() =>
            {
                for (int i = 0; i < enabledShipList.Length; i++)
                {
                    var ship         = enabledShipList[i];
                    var linkedBuffer = linkedBfe[ship];
                    for (int j = 0; j < linkedBuffer.Length; j++)
                    {
                        var e = linkedBuffer[j].Value;
                        if (parentCdfe.Exists(e))
                        {
                            var p         = parentCdfe[e];
                            parentCdfe[e] = p;
                        }
                    }
                }
            }).Run();
1 Like

Thanks for suggestion. I’ve actually started manually adding Child buffer to parent entity and adding childs for it as a temporal workaround (for some reason just dirtying entities didn’t work for me). I hope it will be fixed soon.

Connected issue Instantiate and offset a prefab with disabled children

1 Like