Search Unity

ChangedFilter does not work with DynamicBuffers

Discussion in 'Data Oriented Technology Stack' started by GilCat, Sep 10, 2019.

  1. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    417
    I'm trying to filter out changed DynamicBuffers in IJobForEach using ChangedFilter attribute but it doesn't seem to work.
    Is this intended or bug?
    The workaround i have found is to set filter changed on the query right before scheduling the job.
    Code (CSharp):
    1. EntityQuery.SetFilterChanged(typof(my buffer IBufferElementData))
    Is this a proper way to it?

    EDIT:
    Just doing SetFilterChanged once on the query is enough
     
    Last edited: Sep 10, 2019
  2. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    417
    Ok, it actually works with DynamicBuffers.
    It seem like [ChangedFilter] attribute will only work if you schedule the IJobForeach passing a System, in case you pass an EntityQuery to the job you must explicitly call EntityQuery.SetFilterChanged in order to filter out changed entities.
    Don't know if this is by design but there should be something about it in the documentation.
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,656
    All attributes for IJobForEach only work when you pass in a system - exclude/require/readonly/etc will not do anything either.

    The point of attributes is to use reflection to generate a Query for the job but if you pass in a query there's no need to have this overhead.
     
    GilCat likes this.
  4. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    417
    I'm not sure if that is quiet true. At least if i have an EntityQuery with a ReadOnly component i am forced to put the [ReadOnly] attribute on the IJobForeach otherwise it complains about Iterator must be marked [ReadOnly]
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,656
    Hmm that's interesting, TBH I've never checked I'd always add a ReadOnly attribute anyway. I suspect that is more of a failure with the safety system than creating a new query.
     
  6. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    417
    Yeah i guess so, but that tricked me on thinking it would work on any query supplied to the job.
    Anyway is good to know what works and what doesn't.