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

Need read only access to dynamic buffers

Discussion in 'Entity Component System' started by YurySedyakin, Mar 10, 2020.

  1. YurySedyakin

    YurySedyakin

    Joined:
    Jul 25, 2018
    Posts:
    61
    Hi,
    Have got a problem here. I have got the following system:
    Code (CSharp):
    1.  
    2.     public class MySystem : JobComponentSystem
    3.     {
    4.         protected override JobHandle OnUpdate(JobHandle inputDeps)
    5.         {
    6.             BufferFromEntity<X> xFromEntity = GetBufferFromEntity<X>(true);
    7.  
    8.             return Entities
    9.                 .WithAll<X>()
    10.                 .WithReadOnly(xFromEntity)
    11.                 .ForEach(
    12.                     (in Entity entity) =>
    13.                     {
    14.                         DynamicBuffer<X> x = xFromEntity[entity];
    15.                     }
    16.                 )
    17.                 .Schedule(inputDeps);
    18.         }
    19.     }
    20.  
    The problem with it is that it marks chunks as changed, even though I have passed true into GetBufferFromEntity and did WithReadOnly(xFromEntity).
    Any suggestions?
     
  2. YurySedyakin

    YurySedyakin

    Joined:
    Jul 25, 2018
    Posts:
    61
    OK, I've filed a bug - Case 1236267
     
    msfredb7 likes this.
  3. YurySedyakin

    YurySedyakin

    Joined:
    Jul 25, 2018
    Posts:
    61
  4. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    85
    Thanks! I forwarded it on to the respective team.
     
    msfredb7 likes this.
  5. YurySedyakin

    YurySedyakin

    Joined:
    Jul 25, 2018
    Posts:
    61
    This one is still there, unfortunately. Just so you realize, this restricts people from traversing parent-child hierarchy of entities, because once you READ the children buffer it marks it as changed, which means rebuilding local-to-world matrices, because the transformation systems consider your hierarchy as changed, which is wrong. This is true for other (my own) systems that should take hierarchy changes into account.
     
    lclemens and msfredb7 like this.
  6. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    296
    I'm just wondering, what happens when you remove .WithAll<X>()?
     
  7. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    863
    Sad face
     
  8. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Oh dear...

    Is this bug specific to Entities.ForEach, or does it also affect any use of BufferFromEntity?

    @joepl Any updates on this since April?
     
  9. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    677
    This bug is specific to BufferFromEntity AFAIK, all Buffer access are RW access currently, unfortunately.
     
    PublicEnumE likes this.
  10. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Ah - that makes sense. I remember working around this now: I run a System early in my loop, which just caches a BufferFromEntity, so that later Systems can pass it into multiple jobs which can then run in parallel.

    ...It would be very nice if that wasn't necessary...
     
  11. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    714
    ugh....
     
  12. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    brunocoimbra likes this.
  13. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    I'm excited to hear that it's been fixed, but I can't find any mention of the fix in the changelist you linked. Would you mind quoting the line that explains the fix?
     
  14. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,627
    Fixed a bug with BufferFromEntity<T> which caused it to incorrectly update the version number of the buffer when marked ReadOnly