Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to judge system has IBufferElementData singleton?

Discussion in 'Entity Component System' started by Hello_hxh, Jan 25, 2021.

  1. Hello_hxh

    Hello_hxh

    Joined:
    Nov 24, 2017
    Posts:
    6
    Unity provide the api :ComponentSystemBase.HasSingleton() 。just can use on IComponentData。Here are some way to do it,but I think is not easy :
    1. Use EntityQuery.CalculateEntityCount()
    2. Add IComponentData , and judging by this component。
    3. create all singleton IBufferElementData ,and don‘t judge it,just use ComponentSystemBase.GetSingletonEntity。
    It is strange that you can use GetSingletonEntity() to get a IBufferElementData singleton,but can't use HasSingleton() on IBufferElementData 。and those function internal use the same function : GetSingletonEntityQueryInternal() .
     
  2. Hello_hxh

    Hello_hxh

    Joined:
    Nov 24, 2017
    Posts:
    6
    hello, need some help !! Thank you
     
  3. RecursiveEclipse

    RecursiveEclipse

    Joined:
    Sep 6, 2018
    Posts:
    298
    You can use EntityQuery or SystemBase to get the entity, then use GetComponentDataFromEntity or BufferFromEntity in SystemBase to check if it has the buffer.

    AFAIK there isn't a HasSingleton equivalent/overload for buffer yet.
     
  4. Hello_hxh

    Hello_hxh

    Joined:
    Nov 24, 2017
    Posts:
    6
    thank you very much