Questions on JobSystem

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?

  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)
2 Likes

Thanks, but where do you get all these information from? Do you have any source I can read up more on the subject?

you can read the sources from the ECS package: import it, then (on 2018.2) it will appear under “Packages” in the project window. it’s also on the package cache (on mac is Library/Unity/cache/packages/packages.unity.com/com.unity.entities@)

also:

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?

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.