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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Resolved EntityCommandBufferSystem.AddJobHandleForProducer always necessary?

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

  1. Rupture13


    Apr 12, 2016
    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


    Unity Technologies

    Nov 15, 2018
    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.