Search Unity

Question Keep state of Particle System when disabled? [Unity 2019.4 LTS]

Discussion in 'General Graphics' started by GGsparta, Mar 26, 2021.

  1. GGsparta

    GGsparta

    Joined:
    Aug 25, 2017
    Posts:
    14
    Hello,

    In my scene, I have some beautiful galaxies made on particle systems (1 galaxy = 4 particles system). I need to disable them sometimes, but once I reactive them, the game freezes for ~300ms. On the profiler, I can see the cause is the prewarm of every system on enable. If the prewarm is unchecked, the system takes 100 seconds to reach its full normal state (which is not wanted).

    It just feels stupid to simulate every particle again in prewarm while the only thing I need is to "pause" them while disabled, so I could get them at the same place on enable. I tried to Play/Pause the system or enable/disable emission during OnEnable/OnDisable and OnBecameVisible/OnBecameInvisible, but it doesn't seem to work. I really would appreciate a solution that avoids me getting the system out of my galaxy hierarchy... Any tips?


    upload_2021-3-26_16-24-7.png
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    if you want to keep their state, try:
    * Setting the Culling Mode to Always Simulate (https://docs.unity3d.com/Manual/PartSysMainModule.html)
    * Then, instead of disabling the GameObject, call ParticleSystem.Pause, then get the renderer and set ParticleSystemRenderer.renderMode to None (https://docs.unity3d.com/Manual/PartSysRendererModule.html)

    now they should be paused + hidden, but their state should not get reset.
    so you can simply set the render mode back to Billboard, and unpause them, when you want them back again.
     
    karl_jones likes this.
  3. GGsparta

    GGsparta

    Joined:
    Aug 25, 2017
    Posts:
    14
    Thanks for your reply. So if the particle system is deeper in the hierarchy of a gameobject that should be disabled, the ONLY solution is to get the particle system out of the hierarchy?
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Unfortunately I think so. Pretty sure disabling causes the particles to be cleared out.

    you could do something like GetParticles just before, followed by SetParticles when re-enabled, as an alternative.

    If the prewarm still happens when reenabling, disable that setting too when you do this kind of disabling.
     
    HoneyButterAlmond and GGsparta like this.
  5. GGsparta

    GGsparta

    Joined:
    Aug 25, 2017
    Posts:
    14
    Thank you for your answer! Saving and restoring particles on enable/disable worked for me! I created a little script added on the concerned gameobjects, right above the particle system component so it could save before the system clears the particles.
     
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Great! Glad you figured something out for this!