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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Questions on JobSystem

Discussion in 'Entity Component System' started by ldhongen1990, Jul 26, 2018.

  1. ldhongen1990

    ldhongen1990

    Joined:
    Dec 18, 2015
    Posts:
    61
    Hey guys I am learning ECS + Jobsystem and I have some questions on Jobsystem which I haven't been able to find proper documentations for, anybody can help me out please? If possible, with links to proper docs and some simple code sample, thanks alot

    1. Is it possible to use SubtractiveComponent with IJobProcessComponentData<>?

    2. IJobProcessComponentData only accepts a maximum of 3 types? What if I need more?

    3. Is is safe to mix and match ComponentDataArray (IComponentData) with ComponentArray (Monobehavior) in the same struct and inject them into a JobComponentSystem? (Because migrating to hybrid ecs)

    4. Why do we not use a JobComponentSystem for everything so that we can multi-thread everything?

    5. If we can use IJobParallelFor, why do we still need a regular IJob?

    6. In JobComponentSystem OnUpdate, we call job.schedule, does it run on the same frame? If it doesn't, how do we determine order of execution between systems?
     
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    558
    1) there is a
    RequireSubtractiveComponent
    attribute
    2) a) there is a
    RequireComponentTag
    for empty component data or cd that you don't need to actually access
    b) if you need more you can use
    IJobParallelFor
    and pass
    ComponentDataArray
    to it
    3) yes but you cannot use reference types (class) inside jobs.
    4) same as 3. also most existing unity API cannot be used in jobs (they will provide jobified API, but it will take years to cover everything)
    5) in a
    IJobParallelFor
    you can only write into the current index.
    IJob
    can access the whole arrays and will still be executed in parallel to other jobs
    6) it will run before its output data will be needed or if you use an
    EntityCommandBuffer
    from a barrier system, before that executes. (the job itself has no concept of frame)
     
    LazyMonkey and eizenhorn like this.
  3. ldhongen1990

    ldhongen1990

    Joined:
    Dec 18, 2015
    Posts:
    61
    Thanks, but where do you get all these information from? Do you have any source I can read up more on the subject?
     
  4. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    558
  5. ldhongen1990

    ldhongen1990

    Joined:
    Dec 18, 2015
    Posts:
    61
    Hi MR_R, so for 3),

    a.) so is it safe to read a monobehavior value-type field from the ComponentArray in a job system? Is the value deterministic in nature?
    b.) I cannot write the value back to because ComponentArray containing monobehavior is a read-only array, right?
     
  6. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    558
    no you cannot have
    ComponentArray
    in jobs, because
    MonoBehaviour
    is a class type. period.
    you will need to extract the structs into a
    NativeArray<T>
    in the main thread, and pass that to your job. or better, convert to
    IComponentData


    remember:
    JobComponentSystem.OnUpdate(...)
    is called on the main thread, in there you schedule the job(s) and return the handle.