Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Error at entities@0.5.0-preview.17/Unity.Transforms/ParentSystem.cs:328

Discussion in 'Data Oriented Technology Stack' started by Ryuuguu, Feb 1, 2020.

  1. Ryuuguu

    Ryuuguu

    Joined:
    Apr 14, 2007
    Posts:
    337
    (Error trace below)
    Any suggestions for how to handle or investigate this error? I am creating and destroying a lot of prefabs every frame. There about 450 active prefabs, 150 being created, and 150 being destroyed every frame. Each prefab has root one child which in turn has two children. There are a total of 3.5K entities with 150 non-prefab entities being created and destroyed each frame. Depending on the setup I get this error or the editor just locks up when I reach around 3.5K entities. I am guessing this is a memory problem. my profiler memory has this.

    Used Total: 2.01 GB   Unity: 0.92 GB   Mono: 302.0 MB   GfxDriver: 80.0 MB   Audio: 1.1 MB   Video: 1.0 KB   Profiler: 0.71 GB   
    Reserved Total: 1.54 GB Unity: 413.6 MB Mono: 319.2 MB GfxDriver: 80.0 MB Audio: 1.1 MB Video: 1.0 KB Profiler: 0.75 GB



    Is there a way to check if memory is available before calling instantiate()?

    To get the error message I have "full stack traces" on and Burst compiler off. My asm does not allow unsafe code.

    Code (CSharp):
    1. ArgumentException: The entity does not exist
    2. Unity.Entities.EntityComponentStore.AssertEntityHasComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType componentType) (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/EntityComponentStoreDebug.cs:231)
    3. Unity.Entities.EntityComponentStore.AssertEntityHasComponent (Unity.Entities.Entity entity, System.Int32 componentType) (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/EntityComponentStoreDebug.cs:239)
    4. Unity.Entities.BufferFromEntity`1[T].get_Item (Unity.Entities.Entity entity) (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/Iterators/BufferFromEntity.cs:75)
    5. Unity.Transforms.ParentSystem+GatherChildEntities.Execute () (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Transforms/ParentSystem.cs:328)
    6. Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at /Users/builduser/buildslave/unity/build/Runtime/Jobs/Managed/IJob.cs:30)
    7. Unity.Jobs.JobHandle:ScheduleBatchedJobsAndComplete(JobHandle&)
    8. Unity.Jobs.JobHandle:Complete() (at /Users/builduser/buildslave/unity/build/Runtime/Jobs/ScriptBindings/JobHandle.bindings.cs:20)
    9. Unity.Transforms.ParentSystem:UpdateDeletedParents() (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Transforms/ParentSystem.cs:349)
    10. Unity.Transforms.ParentSystem:OnUpdate(JobHandle) (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Transforms/ParentSystem.cs:365)
    11. Unity.Entities.JobComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/JobComponentSystem.cs:120)
    12. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/ComponentSystemGroup.cs:182)
    13. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/ComponentSystemGroup.cs:169)
    14. Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/ComponentSystem.cs:107)
    15. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/ComponentSystemGroup.cs:182)
    16. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/ComponentSystemGroup.cs:169)
    17. Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/ComponentSystem.cs:107)
    18. Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.5.0-preview.17/Unity.Entities/ScriptBehaviourUpdateOrder.cs:152)
    19.  
     
  2. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    114
    *Following*

    I get the exact same error in
    0.5.1-preview.11
    , (presumably) when I'm removing components from a JobForEach with EndSimulationEntityCommandBufferSystem, which I assumed would be the right way. This happens for maybe 1/100 entities being destroyed.

    Code (CSharp):
    1. public class UnitMoveToTargetSystem : JobComponentSystem {
    2.     private EndSimulationEntityCommandBufferSystem endSimulationEntityCommandBufferSystem;
    3.  
    4.     protected override void OnCreate() {
    5.         endSimulationEntityCommandBufferSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
    6.     }
    7.  
    8.     protected override JobHandle OnUpdate(JobHandle inputDependencies) {
    9.         var job = new UnitMoveToTargetSystemJob {
    10.             deltaTime = UnityEngine.Time.deltaTime,
    11.             translationsFromEntity = GetComponentDataFromEntity<Translation>(false),
    12.             entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
    13.         };
    14.         inputDependencies = job.Schedule(this, inputDependencies);
    15.         endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(inputDependencies);
    16.         return inputDependencies;
    17.     }
    18.  
    19.     [BurstCompile]
    20.     [RequireComponentTag(typeof(UnitTag))]
    21.     struct UnitMoveToTargetSystemJob : IJobForEachWithEntity<Target, MoveSpeed, Rotation> {
    22.         public float deltaTime;
    23.         [NativeDisableParallelForRestriction]
    24.         public ComponentDataFromEntity<Translation> translationsFromEntity;
    25.         public EntityCommandBuffer.Concurrent entityCommandBuffer;
    26.  
    27.         public void Execute(Entity entity, int index, [ReadOnly] ref Target target, [ReadOnly] ref MoveSpeed moveSpeed, ref Rotation rotation) {
    28.             if (translationsFromEntity.Exists(target.targetEntity)) {
    29.                 var unitTranslation = translationsFromEntity[entity];
    30.                 var targetTranslation = translationsFromEntity[target.targetEntity];
    31.  
    32.                 float3 targetDir = targetTranslation.Value - unitTranslation.Value;
    33.                 var lookDirection = targetDir;
    34.                 lookDirection.y = 0;
    35.                 var smoothedRotation = math.slerp(rotation.Value, quaternion.LookRotationSafe(lookDirection, math.up()), 1f * 4 * deltaTime);
    36.                 rotation.Value = smoothedRotation;
    37.                 unitTranslation.Value += targetDir * moveSpeed.moveSpeed * deltaTime;
    38.                 translationsFromEntity[entity] = unitTranslation;
    39.  
    40.                 var distanceSquared = math.distancesq(unitTranslation.Value, targetTranslation.Value);
    41.                 if (distanceSquared < 1f) {
    42.                     /* Close to target, destroy it: */
    43.                     entityCommandBuffer.DestroyEntity(index, target.targetEntity);
    44.                     entityCommandBuffer.RemoveComponent(index, entity, typeof(Target));
    45.                 }
    46.             } else {
    47.                 /* Target Entity already destroyed: */
    48.                 entityCommandBuffer.RemoveComponent(index, entity, typeof(Target));
    49.             }
    50.         }
    51.     }
    52. }
    53.  
    Stacktrace:
    Code (CSharp):
    1. ArgumentException: The entity does not exist
    2. Unity.Entities.EntityComponentStore.AssertEntityHasComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType componentType) (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/EntityComponentStoreDebug.cs:231)
    3. Unity.Entities.EntityComponentStore.AssertEntityHasComponent (Unity.Entities.Entity entity, System.Int32 componentType) (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/EntityComponentStoreDebug.cs:239)
    4. Unity.Entities.BufferFromEntity`1[T].get_Item (Unity.Entities.Entity entity) (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/Iterators/BufferFromEntity.cs:75)
    5. Unity.Transforms.ParentSystem+GatherChildEntities.Execute () (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Transforms/ParentSystem.cs:328)
    6. Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at /Users/builduser/buildslave/unity/build/Runtime/Jobs/Managed/IJob.cs:30)
    7. Unity.Jobs.JobHandle:ScheduleBatchedJobsAndComplete(JobHandle&)
    8. Unity.Jobs.JobHandle:Complete() (at /Users/builduser/buildslave/unity/build/Runtime/Jobs/ScriptBindings/JobHandle.bindings.cs:20)
    9. Unity.Transforms.ParentSystem:UpdateDeletedParents() (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Transforms/ParentSystem.cs:349)
    10. Unity.Transforms.ParentSystem:OnUpdate(JobHandle) (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Transforms/ParentSystem.cs:365)
    11. Unity.Entities.JobComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/JobComponentSystem.cs:120)
    12. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/ComponentSystemGroup.cs:182)
    13. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/ComponentSystemGroup.cs:169)
    14. Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/ComponentSystem.cs:107)
    15. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/ComponentSystemGroup.cs:182)
    16. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/ComponentSystemGroup.cs:169)
    17. Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/ComponentSystem.cs:107)
    18. Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/ScriptBehaviourUpdateOrder.cs:152)
     
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    1,944
    But if your Units have same targetEntity in Target component (for example you have 5 UnitTag entites and they all have same targetEntity in Target) it will race condition, because buffer not beeing played yet and you recording Remove many times
     
  4. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    114
    Thanks @eizenhorn that makes perfect sense. What's the typical ECS approach to solve this? Mark the Targets with some sort of `DestroyTag` and have a ComponentSystem destroy them sequentially with an
    Exists
    check right before?
     
  5. Ryuuguu

    Ryuuguu

    Joined:
    Apr 14, 2007
    Posts:
    337
    There may be a race condition happening when my code runs but it seems to be caused by the Unity Parent/Child system. I only ever destroyed the root of the prefab yet still got errors. I switched from using prefabs with children to manually tracking children and deleting them with my own code and never get errors. Even when destroying 1000s of root entries per frame.
     
unityunity