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. Dismiss Notice

True seamless ParticleSystem looping

Discussion in 'Scripting' started by arturmandas, Feb 15, 2017.

  1. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    Hello,
    Is there a working way to achieve seamless looped particles with PS? I mean like for static particles that should keep their positions between simulations of the particle system.

    I HAVE ALREADY TRIED:
    - turning off auto random seed
    - resimulating/clearin/stoping&playing when simulation time reaches its end.

    This seems a serious issue to me. I am using U 5.4.3

    Best!
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    In scripting, you can set your particleSystem.randomSeed. I know the name is deceiving, but if you set that value to the same number, it will simulate the same way each time.

    A particle system always starts with a random seed. Setting "autoRandomSeed" to true simply disables it from getting a new random seed each time Play() is called.
     
  3. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    Thanks, but that does not work at all, as I've written, I've already tried that.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    Can you provide an example of what you are trying to achieve? Maybe a project file?
     
  5. InvertedCat

    InvertedCat

    Joined:
    Apr 16, 2017
    Posts:
    22
    We have an issue similar to this.
    Particle System is Looped, but not Prewarmed (Smoke rising slowly from a chimney)

    Start ParticleSystem, save time to effectTime.
    Move Camera far away -> Stop particle System
    Move Camera Back -> ParticleSystem.Play and set ParticleSystem.time to Time.time - effectTime
    Particle System starts from the beginning (because it's Looped?) instead of at Time.time - effectTime.
     
    Last edited: Jun 2, 2017
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    Sounds like you want to use Simulate, not time. https://docs.unity3d.com/ScriptReference/ParticleSystem.Simulate.html
    Record the time, call stop and use Simulate with that time to resume it.
     
    InvertedCat likes this.
  7. InvertedCat

    InvertedCat

    Joined:
    Apr 16, 2017
    Posts:
    22
    Thanks a lot! That does the trick, my code snippet for anyone else trying to do it

    Code (csharp):
    1.  
    2. var time = Time.time - chimneyStartTime;
    3. chimneyEffect.Simulate(time,false);
    4. chimneyEffect.Play();
    5.  
    Any idea how efficient the Simulate function is? For example if I have the effect running for 10 min and want to restore it, will it be costly to call Simulate with a high t? The particle system duration is 8 sec looped with particle lifetime of 10 sec. Then again I can probably just consider any t higher 10 as 10. It will not be a perfect restore but not noticeable in my case.
     
    karl_jones likes this.
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    It could be quite costly if its a none procedural system. https://blogs.unity3d.com/2016/12/20/unitytips-particlesystem-performance-culling/
     
    InvertedCat likes this.
  9. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    Thanks guys! Will try that approach!