Search Unity

Particle System Flickering

Discussion in 'Scripting' started by Avestas, Dec 21, 2014.

  1. Avestas

    Avestas

    Joined:
    Jun 8, 2013
    Posts:
    17
    Hey there:

    What I want to do is making a burst of particles via Code for a specific time.
    After that amount of time, I want to stop the particle system and let it return to its usual behavior.
    I use the following Code to end the burst:

    Code (JavaScript):
    1. function fadeStream(){
    2.     Debug.Log(particleSystem.emissionRate);
    3.     var tmpTime:float=0;
    4.     var oldRate:float=1000000;       //to exit the function, if a new boost is started during the fade
    5.     while(particleSystem.emissionRate>1){
    6.         if(particleSystem.emissionRate>oldRate){
    7.             internSoftOff=true;
    8.             return;
    9.         }
    10.         particleSystem.emissionRate=particleSystem.emissionRate*Mathf.Exp(-2*tmpTime)+1;
    11.         tmpTime+=Time.deltaTime;
    12.         oldRate=particleSystem.emissionRate;
    13.      
    14.  
    15.      
    16.     yield;
    17.  
    18.     }
    19.     internSoftOff=true;
    20.     particleSystem.startLifetime=baseLifeTime;
    21.     particleSystem.startSpeed=baseSpeed;
    22. }
    When the boost ends, no new particles are emitted, as intended:

    The problem is: The already emitted particles do not fade out smoothly as configured in the particle system. During the boost everything behaves right, but about 1/3 second after the emission stops, the "old" particles just disappear, sometimes they even flicker back for a frame...

    Hope you have an idea and thanks in advance!

    Sincerely Vorthos


    EDIT: Seems the problem does not occur, when the particleEmission is not set near 0 at the end...
     
    Last edited: Dec 21, 2014