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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

IJobForEach_B - Dynamic Buffer is write only

Discussion in 'Entity Component System' started by Sarkahn, May 20, 2019.

  1. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Like the title says, I can't read the length of my dynamic buffer in IJobForEach_B or IJobForEachWithEntity_EB. This code:
    Code (CSharp):
    1.  
    2.  
    3. [Serializable]
    4. [InternalBufferCapacity(4)]
    5. public struct CollisionBuffer : IBufferElementData
    6. {
    7.     public Entity value;
    8.     public static implicit operator Entity(CollisionBuffer col) { return col.value; }
    9.     public static implicit operator CollisionBuffer(Entity e) { return new CollisionBuffer { value = e }; }
    10. }
    11.  
    12. public class DynamicBufferJobTest : JobComponentSystem
    13. {
    14.     struct ProcessBuffers : IJobForEach_B<CollisionBuffer>
    15.     {
    16.         public void Execute( [ReadOnly] DynamicBuffer<CollisionBuffer> b0)
    17.         {
    18.             if( b0.Length == 0 )
    19.             {
    20.  
    21.             }
    22.         }
    23.     }
    24.  
    25.     protected override JobHandle OnUpdate(JobHandle job)
    26.     {
    27.         job = new ProcessBuffers
    28.         {
    29.         }.Schedule(this, job);
    30.  
    31.         return job;
    32.     }
    33.    
    34. }
    Produces this error:
    InvalidOperationException: The native container has been declared as [WriteOnly] in the job, but you are reading from it.


    Is it supposed to work this way?
     
  2. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    that looks like a bug. It seems the [ReadOnly] attribute isn't correctly respected yet.
     
    Sarkahn likes this.
  3. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Fair enough, back to using BufferFromEntity for now I guess
     
  4. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    I just encountered this with IJobForEachWithEntity_EBBC version as well(not using any attributes but getting the write only error)
     
  5. Deleted User

    Deleted User

    Guest

    Replace all BufferFromEntity with IJobForeach_B, otherwise it will throw this error.
     
  6. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    ?? The whole point is I was trying to stop using BufferFromEntity. The error occurs in my original post as it was written.
     
  7. Deleted User

    Deleted User

    Guest

    I had this problem as well. Replaced every IJobForEachWithEntity implementation with IJobForeach_B started to work normally with no crashes or exceptions.
     
  8. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Oh you mean replace it in every single job for a project, I see. Good to know that works but I'm assuming that's still a bug and not at all intended
     
    Deleted User likes this.
  9. AriaBonczek

    AriaBonczek

    Unity Technologies

    Joined:
    Jul 20, 2018
    Posts:
    26
    Yes this looks like a bug. Adding this to our internal tracking.
     
    Silve, Shinyclef, sngdan and 2 others like this.
  10. nttLIVE

    nttLIVE

    Joined:
    Sep 13, 2018
    Posts:
    80
    Doesn't do anything for me. Both IJobForEach and IJobForEachWithEntity throw the error.
     
    Deleted User likes this.
  11. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,131
    .AsNativeArray() creates the same error as .Length --- this should also be possible in ReadOnly mode
     
  12. yossi_horowitz_artie

    yossi_horowitz_artie

    Joined:
    Jan 30, 2019
    Posts:
    87
    Hi @AriaBonczek -- hate to be a nudge, but I was wondering if there's an ETA on a fix for this, or if I should start changing my jobs back to using BufferFromEntity. Thanks!
     
    Egad_McDad and Shinyclef like this.