Search Unity

How to do inverse ComponentGroup filter and get all entities that does not match?

Discussion in 'Entity Component System' started by 5argon, Jun 25, 2018.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I am trying the `SerializeUtility` and the main problem is it must serialize the whole world. There is `EntityManager.MoveEntitiesFrom` to move ALL entities to my save world and then I want to make it so that only what I want remains meaning that I have to destroy everything else.

    Currently only `entityManager.DestroyEntity(componentGroupFilter)` comes to mind but it destroy all matched entities. Any approach to make it the other way that the matched entities remains?

    (Also I cannot GetComponentGroup of the save world via save world's entityManager alone? How to filter in other world while you are in default world's code?)

    Code (CSharp):
    1.         //We are in DefaultWorld's ComponentSystem code.
    2.  
    3.         World saveWorld = new World(nameof(saveWorld));
    4.         var emSave = saveWorld.CreateManager<EntityManager>();
    5.         emSave.MoveEntitiesFrom(EntityManager);
    6.  
    7.         emSave.DestroyEntity( ??? );
    8.  
    9.         SerializeUtility.SerializeWorld(emSave, binaryWriter, out _);
     
    Last edited: Jun 25, 2018
  2. capyvara

    capyvara

    Joined:
    Mar 11, 2010
    Posts:
    80
    Can't you add a tag component to each "saveable" entity and use a subtractive component query? i.e. delete all entities that doesn't have that component?

    EntityManager.DestroyEntity(GetComponentGroup(ComponentType.Subtractive<Saveable>()));