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

Best practise to create Entity in IJobProcessComponentData?

Discussion in 'Entity Component System' started by zephyr831125, Mar 1, 2019.

  1. zephyr831125

    zephyr831125

    Joined:
    Mar 4, 2017
    Posts:
    54
    Hi, I currently uses ComponentSystem and EntityCommandBuffer of barrier to create entities. But I know the formal way needs all jobs previous to be done, not working well with paralleled job systems. And the latter way need injection of BarrierSystem which is obseleted now.

    So how do I create entities better now?
     
  2. kork

    kork

    Joined:
    Jul 14, 2009
    Posts:
    280
    You basically have little choice here. If you want to create an entity in a job you need a command buffer as you don't have an
    EntityManager
    there. I am unaware of any different API. Injection per se is not deprecated, just ECS's
    [Inject]
    . You can still use a dependency injection framework to inject your barrier (see https://forum.unity.com/threads/how...ction-and-reactive-programming-in-ecs.636256/) or use the static
    World.Active.GetOrCreateManager<SomeBarrier>()
    to get hold of a barrier (though I would suggest you use dependency injection as this makes the systems easier to test).
     
  3. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    On ComponentSystem you have PostUpdateCommands available where you don't need to inject any other command buffer on JobComponentSystem you are to inject barriers and pass them to your job.
     
  4. AriaBonczek

    AriaBonczek

    Unity Technologies

    Joined:
    Jul 20, 2018
    Posts:
    26
    Regarding BarrierSystems, you can still use them without injection as kork mentions by calling
    World.Active.GetOrCreateManager<SomeBarrier>()
    . You would cache a reference to the BarrierSystem into a field and at the end of the system loop call
    myBarrierSystem.AddJobHandleForProducer(yourOutputJobHandle)
    with the JobHandle that the BarrierSystem must wait on before executing your EntityCommandBuffer.

    The next release of samples will have a good example of this. The sample is called HelloCube_06 and the system with the example is
    HelloSpawnerSystem
     
  5. zephyr831125

    zephyr831125

    Joined:
    Mar 4, 2017
    Posts:
    54
    Great! thank you!
     
  6. zephyr831125

    zephyr831125

    Joined:
    Mar 4, 2017
    Posts:
    54
    Thank you!