- Home /
Particle system does not re-emit until Start Lifetime elapsed
Hi,
I am using the particle system to create a gun emission effect that should occur as soon as the player presses fire. In the Update function the particle system is started when the player presses fire and stopped/cleared when they aren't pressing it - even if I place the stop/clear code prior to emitting, the system refuses to emit particles until the Start Lifetime timer has elapsed. Obviously this is not the desired behaviour as the emission is then intermittent and not immediate.
I have tried setting max particles to a high value and emission rate to a low value + several other tests but I am becoming convinced the particle system ignores any attempt to re-emit (even after clearing etc) until the Start Lifetime has elapsed since the last emission.
Any ideas what I can do to remedy this?
Thanks.
Answer by Piflik · May 09, 2012 at 10:01 AM
I would instantiate the particle system on ButtonDown and destroy it on ButtonUp, instead of controlling the emission rate.
Answer by RGravity · May 09, 2012 at 01:49 PM
Would this not cause undue garbage collection? I've mostly written mobile games over the last few years and creating/destroying objects at runtime is something I've learned to avoid like the plague.
Also I'm not attempting to dynamically control the emission rate as such, simply stopping and clearing/restarting the system, which intuitively I would have thought would do the job.
Answer by RGravity · May 09, 2012 at 02:02 PM
Ok this text may appear several times as it's the 3rd time I've posted a reply in the hope it will appear sometime!
Anyway, won't your suggestion cause unnecessary garbage collection? I've mostly worked with mobile platforms and I know to avoid creating/destroying objects at runtime like the plague.
Also I'm not trying to dynamically control emission but simply stopping, clearing/restarting the emitter which, intuitively, I would expect to just work.
Thanks.
"Ok this text may appear several times as it's the 3rd time I've posted a reply in the hope it will appear sometime!"
Until your karma level reaches 15+ any answers/questions you post have to go through moderation, and re-posting them doesn't speed up the process (it simply results in duplicate posts being displayed after they've cleared moderation).
For adding comments, rather than posting comments as answers, theres an "add new comment" box at the bottom-right of answer/question posts (which get displayed immediately).
Answer by RGravity · May 09, 2012 at 02:57 PM
I've managed to solve this )) it was my faulty understanding (I'm new to unity). I unchecked Looping, changed duration to 1.00 and reduce the Start Lifetime, then used particlesystem.Emit(1) in Update to emit a particle per frame while the fire button is held. Works nicely but I suspect the 1 may need to be made framerate-independent somehow.
Somehow? Create a rolling count ivar.
float _emitRollingCount = 0.0f;
public float emitRate = 1.0f;
void Update()
{
_emitRollingCount += this.emitRate * Time.deltaTime;
if (_emitRollingCount >= 1.0f) {
int emitNowCount = (int)$$anonymous$$athf.Floor(_emitRollingCount);
_emitRollingCount -= emitNowCount;
this.particleSystem.Emit(emitNowCount);
}
}
Your answer
Follow this Question
Related Questions
How to pause emitter in new Particle System? 2 Answers
Particle System(Shuriken) optimization problem 1 Answer
Shuriken particles - strange load CPU with ParticleSystem.Update 4 Answers
Multiple trails behind one particle? 1 Answer
Separate particle systems rendered together with a single sorting mode? 0 Answers