Search Unity

DestroyAndResetAllEntities ArgumentException ISystemStateComponentData

Discussion in 'Entity Component System' started by JooleanLogic, Mar 6, 2022.

  1. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    In trying to remove all entities before changing scenes using EntityManager.DestroyAndResetAllEntities(), I get an "ArgumentException: Destroying all entities failed. Some entities couldn't be deleted."
    There's no other details in exception but I worked out it was due to having
    ISystemStateComponentData's on some entities.

    This makes sense but the documentation and Exception make no mention of this. I wonder would it make sense for Unity to add flag options to this which allow to delete all entities including those with
    ISystemStateComponentData (same as EntityManager.DestroyEntity()) thus allowing for normal cleanup, or to even just delete all entities immediately ignoring ISystemStateComponent functionality? Kind of a Shift+Delete, do not pass Recycle Bin option.

    Only option I know for now is EntityManager.DestroyEntity(EntityManager.GetAllEntities()) which still allows for delayed cleanup on first frame of newly loaded scene. Are there other ways of removing all entities for scene changes?