Search Unity

Barrier after Inject

Discussion in 'Entity Component System' started by FrankvHoof, Apr 6, 2019.

  1. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    Now that Injection is being (/has been) deprecated, how does one create/get a barrier (in order to add/remove components from a job)?
     
  2. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    in the absolute latest package, just do the following:

    Code (CSharp):
    1. ... OnCreateManager()
    2. {
    3.    m_CommandBufferSystem = EntityManager.GetOrCreateSystem<DesiredCommandBufferSystem>();
    4. }
    There's been some API changes, BarrierSystems have been renamed to CommandBufferSystems. EntityManager's GetOrCreateManager<T>() and related calls have been renamed to GetOrCreateSystem and so on.
     
    FrankvHoof likes this.
  3. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    I'm on the latest version (0.0.12-preview.30 w/ Unity 1029.2.0a9), but GetOrCreateSystem does not seem to exist... (Edit: nvm found it in World.Active)
    Besides that, EntityCommandBufferSystem seems to be a class, so would I still be able to use that in a job? (Edit 2: Found the .CreateCommandBuffer().. Thanks for the help ;))
     
    recursive likes this.
  4. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    No problem!

    One thing to note, that may not be obvious:

    You will now need to register a job handle that uses ECB or ECB.Concurrent to the commandBufferSystem via
    EntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);
    as that lets the system know to wait on the job completion before executing any buffers.
     
  5. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    Hmmm.. Running the Job seems to throw exceptions for some reason..


    ArgumentException: The previously scheduled job SelectClosestIntersectionJob writes to the NativeArray SelectClosestIntersectionJob.Buffer. You must call JobHandle.Complete() on the job SelectClosestIntersectionJob, before you can write to the NativeArray safely.
    EntityCommandBuffer was recorded in Systems.SelectionSystem and played back in Systems.SelectionSystem+SelectionCommandBufferSystem.


    Where my job looks like this:

    https://gyazo.com/f4bcd8a361b330d3f2f3427630ececd0
     
  6. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    See my edit above.
     
  7. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669