not able to disable trail renderer

In my game my plane is firing missiles, I had made a missile pool which resets the missiles when they are out of view(OnBecameInvisible()) and then reuse them by setting up new values.
Missile have trail renderer.
what i did in


  • OnBecameInvisible()

    • trailRenderer.enable = false;
    • trailRenderer.time =0;
    • gameObject.SetActive(false);
  • when re using

    • trailRenderer.enable = true;
    • trailRenderer.time =1;
    • gameObject.SetActive(true);

now what happens is a trail is drawn when from a point outside view to the point where i am firing missiles, just a flash and then normal missile with trail is rendered.

GetComponent().Clear();

Hey…

i just stumbled on exactly the same issue, looking the web for solutions. It´s really weird that it´s hard to find an answer to this, wich involves NOT destroying and instantiating the particle, or the trailrenderer component (wich we want to avoid, when using a pooling system)

Anyway, i found a solution:

use this, when you disable and recycle the particle in your pool

myTrail.time = 0.01f;

and set it back to your chosen value, after respawning. The trick here is, that the setback MUST happen one frame, AFTER the particle gets translated to it´s new position. otherwise the trailrenderer will render the setback in the same frame after you setback your original value for the time.

For the next one banging his head against this!