Search Unity

Resolved EntityCommandBufferSystem.AddJobHandleForProducer always necessary?

Discussion in 'DOTS Dev Blitz Day 2022 - Q&A' started by Rupture13, Dec 8, 2022.

  1. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    131
    The documentation for using EntityCommandBuffer(System)s describes the need to call the AddJobHandleForProducer method on the ECBSystem from wherever you use the corresponding ECB.

    However, as I understand it, this method merely functions as a way to make sure the command-producing job is finished before the ECBSystem plays back its commands. If I have systems and jobs that execute a good while before the ECBSystem and are practically guaranteed to be finished by the time the ECBSystem runs, isn't it superfluous to add it's jobhandle to the ECBSystem's dependency?
     
  2. kevinmv

    kevinmv

    Unity Technologies

    Joined:
    Nov 15, 2018
    Posts:
    51
    You're correct the AddJobHandleForProducer call is indeed to ensure that we wait for all jobs writing to the ECB to complete before we start reading from the ECB. While you may have your writing jobs finish much earlier than the ECB playback, you should (must for correctness) still include the dependency in the job graph. Adding the dependency will ensure correctness and does not add overhead to the ECB playback if your writing jobs are finishing earlier. If they don't, the overhead is that we will wait for them to complete on the main thread as we start ECB playback.
     
    Rupture13 likes this.