Search Unity

DestroyAndResetAllEntities returns error Destroying all Entities failed.

Discussion in 'Entity Component System' started by RobbGraySBL, Apr 15, 2021.

  1. RobbGraySBL

    RobbGraySBL

    Joined:
    Feb 4, 2014
    Posts:
    40
    Trying to save and restore a world state. I'm using

    Code (CSharp):
    1. simulationWorld.EntityManager.DestroyAndResetAllEntities();
    2. simulationWorld.EntityManager.CopyAndReplaceEntitiesFrom(World.EntityManager);
    3. simulationWorld.SetTime(new Unity.Core.TimeData(World.Time.ElapsedTime, World.Time.DeltaTime));
    But depending on some seemingly arbitrary situations I get this. For instance if I have a SpriteRendererComponent on it it fails, but it doesn't fail with a RenderMeshComponent, but does if the RenderMeshComponent is a child.

    ArgumentException: Destroying all entities failed. Some entities couldn't be deleted.
    Unity.Entities.EntityManager.DestroyAndResetAllEntities () (at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/EntityManagerCreateDestroyEntities.cs:168)
    Tests.RollbackTests.CreateSnapShot (Unity.Entities.World snapShotWorld, Unity.Entities.World world) (at Assets/Tests/Scripts/RollbackTests.cs:62)
    Tests.RollbackTests.Update () (at Assets/Tests/Scripts/RollbackTests.cs:50)

    If there's a better way to save/restore a world that's all I'm looking for.

    Thanks.
     
  2. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    866
    try removing simulationWorld.EntityManager.DestroyAndResetAllEntities();
     
  3. nykwil

    nykwil

    Joined:
    Feb 28, 2015
    Posts:
    49
    Same user just switching accounts. I removed DestroyAndResetAllEntitites,but I'm getting this eventual crash, it seems to work a few times saving a restoring states but then at some point I get this:

    Unity.Entities.EntityComponentStore.AssertEntityHasComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType componentType) (at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/EntityComponentStoreDebug.cs:281)
    Unity.Entities.EntityComponentStore.AssertEntityHasComponent (Unity.Entities.Entity entity, System.Int32 componentType) (at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/EntityComponentStoreDebug.cs:287)
    Unity.Entities.EntityDataAccess.GetSharedComponentData[T] (Unity.Entities.Entity entity) (at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/EntityDataAccess.cs:1195)
    Unity.Entities.EntityManager.GetSharedComponentData[T] (Unity.Entities.Entity entity) (at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/EntityManagerAccessComponentData.cs:215)
    Battle.BattleGameState.TickCharacters (System.Int64[] inputs) (at Assets/BattleUgg/Scripts/BattleGameState.cs:49)
    Battle.BattleGameState.Update (System.Int64[] inputs, System.Int32 disconnect_flags) (at Assets/BattleUgg/Scripts/BattleGameState.cs:151)
    SharedGame.LocalGame.RunFrame () (at Assets/SharedGame/Scripts/LocalGame.cs:22)
    SharedGame.GameManager.Update () (at Assets/SharedGame/Scripts/GameManager.cs:78)


    Thanks again.
     
  4. redwren

    redwren

    Joined:
    Aug 2, 2019
    Posts:
    69
    I'm getting similar exceptions. Curious if anyone has actually figured out how to use
    CopyAndReplaceEntitiesFrom
    without these assertion exceptions. Pausing execution at the exception shows really weird results in the Entity Debugger, like 4 instances of Entity 6 for example.
     
  5. nykwil

    nykwil

    Joined:
    Feb 28, 2015
    Posts:
    49
    I created a simple repro for the bug and it is now logged but there hasn't been any activity on it. https://issuetracker.unity3d.com/is...eplaceentitiesfrom-and-causes-player-to-crash

    This has put my ECS rollback system on hold until it gets fixed which is really unfortunate. If there is another method to do this easily (backup a world and restore it) then I could use that in it's place until this is fixed. I have gone down a couple of rabbit holes already with copying entities and serializing to memory both required a lot of work. It's hard to invest into that work when the real solution is just two lines of code that don't work properly right now but may be fixed at any time.
     
  6. cort_of_unity

    cort_of_unity

    Unity Technologies

    Joined:
    Aug 15, 2018
    Posts:
    98
    We've tested the repro case against the next major Entities package release, and it no longer reproduces. I'll see if I can figure out what the fix was, and if it's reasonably self-contained we'll backport it to Entities 0.51.
     
    redwren and Anthiese like this.
  7. nykwil

    nykwil

    Joined:
    Feb 28, 2015
    Posts:
    49
  8. nykwil

    nykwil

    Joined:
    Feb 28, 2015
    Posts:
    49
    @cort_of_unity
    Unfortunately the error still occurs, and now it crashes the editor.

    I updated the test with 2022.2.0b8 and Entities 1.0.0-exp.8.
    https://github.com/nykwil/EcsRollbackTest

    If there's anything I can do to help this out I have to make a big technology decision in November. Easy state restoration is a big part of it.

    Thank you

    ArgumentException: All entities passed to EntityManager must exist. One of the entities has already been destroyed or was never created. Entities Journaling may be able to help determine more information. Please enable Entities Journaling for a more helpful error message.
    Unity.Entities.EntityComponentStore.AssertEntitiesExist (Unity.Entities.Entity* entities, System.Int32 count) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/EntityComponentStoreDebug.cs:276)
    Unity.Entities.EntityDataAccess.InstantiateInternalDuringStructuralChange (Unity.Entities.Entity srcEntity, Unity.Entities.Entity* outputEntities, System.Int32 count, Unity.Entities.SystemHandle& originSystem) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/EntityDataAccess.cs:2415)
    Unity.Entities.EntityManager.Instantiate (Unity.Entities.Entity srcEntity) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/EntityManager.cs:3441)
    EcsWar.BoltEmitSystem.BoltEmitSystem_3A264F59_LambdaJob_0_LambdaBody (Unity.Entities.Entity playerEntity, EcsWar.Player& player, Unity.Transforms.Translation& playerTr, Unity.Transforms.Rotation& playerRot) (at Temp/GeneratedCode/EcsWar.Runtime/BoltSpawnSystem__System_1653271636.g.cs:62)
    EcsWar.BoltEmitSystem+BoltEmitSystem_3A264F59_LambdaJob_0_Job.RunWithStructuralChange (Unity.Entities.EntityQuery query) (at Temp/GeneratedCode/EcsWar.Runtime/BoltSpawnSystem__System_1653271636.g.cs:43)
    EcsWar.BoltEmitSystem.BoltEmitSystem_3A264F59_LambdaJob_0_Execute () (at Temp/GeneratedCode/EcsWar.Runtime/BoltSpawnSystem__System_1653271636.g.cs:81)
    EcsWar.BoltEmitSystem.OnUpdate () (at Assets/EcsWar/Runtime/Scripts/BoltSpawnSystem.cs:11)
    Unity.Entities.SystemBase.Update () (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/SystemBase.cs:418)
    Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/ComponentSystemGroup.cs:670)
    UnityEngine.Debug:LogException(Exception)
    Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Stubs/Unity/Debug.cs:19)
    Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/ComponentSystemGroup.cs:675)
    Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/ComponentSystemGroup.cs:628)
    Unity.Entities.SystemBase:Update() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/SystemBase.cs:406)
    CustomUpdateSystem:FixedUpdate() (at Assets/Tests/Runtime/Scripts/CustomUpdateSystem.cs:49)
     
    bb8_1 and redwren like this.
  9. nykwil

    nykwil

    Joined:
    Feb 28, 2015
    Posts:
    49
    Just wanted to say that I tried to re-open this bug and it got approved but the bug is logged as a memory profiler crash and not the ECS bug. Because the memory profiler causes the editor to crash. (IN-18232)

    But the ECS bug is this one https://issuetracker.unity3d.com/is...eplaceentitiesfrom-and-causes-player-to-crash.

    You should probably re-open that one but use the dump/project from https://unity3d.atlassian.net/servicedesk/customer/portal/2/IN-18232 which has logs and repro steps running 1.0.

    I will also keep this repo up to date with any Unity/package updates.

    https://github.com/nykwil/EcsRollbackTest

    @cort_of_unity
     
    RobbGraySBL likes this.