How to set particle emission rate at run time?
ParticleSystem p; p.emission.rateOverTime = 20f;
Keep on telling me that I can't do that, tried other solutions like: ParticleSystem p; var em = p.emission; em.rateOverTime = 20f; p.emission = em;
Does not work either. How do you change particle rate over time during run time?
Answer by Sayama · May 26, 2020 at 05:57 AM
Well, I'm a bit late (3 years) BUT, because I was in the situation, I have a solution! Basically, you have to manually emit the number of particle you want and disable the particle generation beforehand.
 (Rate over Time = 0)
 In my example, I want to set the number of particles according to my speed :
 using UnityEngine;
 
 public class ExempleParticuleSetter : MonoBehaviour
 {
     private ParticleSystem particleSystem;
     //In my exemple, x = min & y = max
     [SerializeField] private Vector2 minMaxEmmiter = new Vector2(0,80);
     [SerializeField] private Vector2 minMaxSpeedDesire = new Vector2(80,200);
 
     //Other variable I need
     private Rigidbody rb;
 
     private void Start()
     {
         particleSystem = GetComponentInChildren<ParticleSystem>();
         
         rb = GetComponent<Rigidbody>();
     }
 
     private void Update()
     {
         //Get the number of particle to emit by some little calculation
         var speed = rb.velocity.magnitude;
         var t = (speed - minMaxSpeedDesire.x) / (minMaxSpeedDesire.y);
         var particleToEmit = (int) Mathf.Lerp(minMaxEmmiter.x, minMaxEmmiter.y, t);
         //Here I Emit my particle
         particleSystem.Emit(particleToEmit);
     }
 }
In this example, when the speed is below "$$anonymous$$$$anonymous$$axSpeedDesire.x" is equal to 0 and so, the Lerp function will set the number of particle "particleToEmit" (I could have set a better name) to 0, and so, no emission.
But in other type of script, you can put a public Boolean et toggle it within other scripts. this way, the last particle will die and don't emit, like this :
 if (urBoolean)
 {
     particleSystem.Emit(particleToEmit);
 }
Your answer
 
 
             Follow this Question
Related Questions
change emission rate of particles in update -> Unity 5.3 0 Answers
ParticleSystem emission rate is incomprehensible. 0 Answers
Cannot Change emission.rate 3 Answers
Low particle emission rate 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                