Search Unity

Feedback Particle System C# Job System support

Discussion in 'Particle System Previews' started by richardkettlewell, May 1, 2018.

  1. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,311
    I'd love to hear your numbers for the particle jobs if you are happy to share them! Remember to use [BurstCompile] on your jobs! ;)
     
    TeotiGraphix likes this.
  2. mnarimani

    mnarimani

    Joined:
    Mar 27, 2017
    Posts:
    214
    Is this feature automatically activated for Unity 2019.3.0a9+?
    Also, do you have any plans on developing particle systems for ECS?
     
    Opeth001 likes this.
  3. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,311
    Yes :)

    No plans; it probably won’t happen for the current Particle System.
     
  4. KokkuHub

    KokkuHub

    Joined:
    Feb 15, 2018
    Posts:
    94
    What is even the point of running the particles on another thread if the main thread sits idle waiting for it to finish?
    upload_2020-1-6_21-15-55.png
     
  5. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,311
    If you have more than one particle system to update, they should run in parallel (unless it's a sub-emitter) Indeed for the singular case it's sub-optimal.
     
  6. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    84
    Hello!
    Where and when Particle System Jobs would be available in public build?
     
  7. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,311
    It’s shipping in 2019.3 :) can use the final version in any recent beta version.

    An experimental version exists in 2019.1 and 2019.2 but we made breaking changes for 2019.3, so best to start there if possible. Who knows, maybe it’ll make it out of beta soon... ;-)
     
    konsic likes this.
  8. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    84
    Found your similar answer in some PS-Jobs thread (^ thank you for clarifications! Unfortunatly, I'd can not use PS-Jobs in production, 'cause 2019.3 would realy non-production ready and migration would be painful, but we're shipping in march 2020 :( Would experiment with it. Planning to replicate Legacy Lens Flare System with it
     
  9. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    537
    Hello Everyone :)

    sorry if my Question looks stupid :p, but what's the benefits of using the IJobParticleSystem knowing that sadly there is no way to complement it with ECS ?
    1) is it only for Complexe Particale systems and used to free the main thread by running everything in worker threads ?
    2) is it worth using it even for simple particle systems ?

    Thanks in advance!
     
  10. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    84
    I've few more questions:
    - IJobParticleSystemParallelFor is not IJobParallelFor ? This mean, that I can't combinate it with other IJobParallelFor?
    - Somewhere you've write that PS-Jobs should be Scheduled int MonoBehaviour callback
    OnParticleUpdateJobScheduled. But where it can be created,in MonoBehaviour.Update? FixedUpdate, [UpdateBefore(typeof(Update)]ComponentSystem.OnUpdate?
     
  11. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,311
    Hey! Not a stupid question ;)

    C# Jobs and Burst work very well with the MonoBehaviour workflow. If you ever wrote ParticleSystem.SetParticles or ParticleSystem.GetParticles in your MonoBehaviour scripts, you could use this new feature to do it much more efficiently.

    1) Freeing up the main thread is indeed a great reason to use this. Even doing something on 100 particles on the main thread probably has a non-negligible cost. I would always suggest measuring. Perhaps the cost of setting up and scheduling a job, to do something simple on 5 particles, might not be worth it, especially if the job needs lots of inputs. There will be a tipping point.

    2) Same as 1) really ;-)
     
    mitaywalle and Opeth001 like this.
  12. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,311
    Correct, it has its own job type because the particle data is passed in, and the for-loop count is predetermined based on the particle count. But it uses the same JobFences as the rest of the job system, so it can be used in dependency-chains with the regular job types.

    Yes, it must be scheduled in OnParticleUpdateJobScheduled. This is to ensure that it does not collide with the built-in update that Unity runs, based on the modules you have enabled in the Inspector.

    If you have other jobs that you want to run as dependencies, you can do it, because the script functions run is a well-defined order:

    FixedUpdate: Schedule a job
    Update: Schedule a job that depends on the first job
    OnParticleUpdateJobScheduled: Schedule the particle job, make it depend on the Update job (i.e. if it has an input that is calculated by the Update job)
    LateUpdate: Scheduling a particle job also returns a JobFence. So you can schedule more jobs here that run using the output of the particle job. Or you can simply schedule more jobs directly in OnParticleUpdateJobScheduled.

    wrt ComponentSystem.OnUpdate.. I'm not very familiar with using ECS and MonoBehaviours together, but I suspect that it's not easy/possible.
     
    mitaywalle likes this.
  13. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    1,336
    Although we've not got particles working in Jobs yet, in one of our assets, Sci-Fi Ship Controller, we have ECS working with MonoBehaviours. Our main ship physics etc code runs as a monobehaviour and there is an option to run projectiles through our weapons system as Entities (updated in parallel with Jobs). If ECS / DOTS is enabled, we also do ray casting in a job.

    Recently we've got some interaction working with the new DOTS-based Unity Physics too. So, it is definitely possible - although not that obvious how it should work together.

    As tools developers, we took this approach because we figured for the foreseeable future people would want to combine monobehaviours (which everyone knows) and DOTS / ECS.

    Certainly having the option of running some of our particle systems with DOTS is appealing - although we understand they are very different from what we currently think of in terms of particles.
     
    richardkettlewell likes this.
  14. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    84
    Thanks for clarifications! Would continue to experiment
     
    richardkettlewell likes this.
unityunity