Search Unity

Question Remove DynamicBuffer

Discussion in 'Entity Component System' started by xseagullx, Jul 23, 2021.

  1. xseagullx

    xseagullx

    Joined:
    Nov 7, 2019
    Posts:
    24
    I feel so stupid asking that, but how do you remove the buffer attached to entity?
    Also, how do I exclude entities with buffer from my query?
    I can't see neither EntityCommandBuffer.RemoveBuffer, nor an option to do `WithNone(Buffer)`.
     
  2. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    987
    We rarely use Entities.ForEach() so we make our own queries using GetEntityQuery(). ComponentType.Exclude<YourBuffer>() can be specified with it but I'm not sure if this would work.
    Code (CSharp):
    1. this.query = GetEntityQuery(ComponentType.Exclude<YourBuffer>(), ... other types);
     
    xseagullx likes this.
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    You just use RemoveComponent<BufferType> and WithNone<BufferType>
     
    xseagullx likes this.
  4. xseagullx

    xseagullx

    Joined:
    Nov 7, 2019
    Posts:
    24
    Thank you very much!

    Now when you point it out, it actually makes sense. But it's so not obvious o_O
     
  5. xseagullx

    xseagullx

    Joined:
    Nov 7, 2019
    Posts:
    24
    Actually, it's even more confusing, as you can not combine normal components and buffer components in WithNone. That made me think it's impossible to filter it this way.

    Code (CSharp):
    1. // does not compile
    2. Entites
    3. .WithNone<MyBufferElement, MyOtherComponent>()
    4.  
    5. // works
    6. Entites
    7. .WithNone<MyBufferElement>()
    8. .WithNone<MyOtherComponent>()