Search Unity

Question Pooled particle system with ribbon

Discussion in 'General Graphics' started by Derakon, Jul 23, 2020.

  1. Derakon

    Derakon

    Joined:
    Jul 3, 2019
    Posts:
    20
    The goal: a visual effect for a very high-speed bullet, which leaves a trail behind it that goes from yellow to red to transparent.

    The implementation: a particle system with a ribbon trails module:
    https://i.imgur.com/WdyYL8n.png

    The problem: when I pool the particle system and try to re-use it, the trail will snap from the last position of the old position to the first position of the new system:
    https://i.imgur.com/MAAAAWC.mp4

    How do I "cut" a ribbon trail effect and start a new ribbon using only newly-created particles?

    Things I have tried to fix this:

    - Stopping the particle system with the StopEmittingAndClear behavior
    - Invoking ParticleSystem.Clear
    - Setting the particle system's trail lifetime to 0 and simulating the particle system for a half-second, then restoring the lifetime
    - Invoking ParticleSystem.GetTrails() before the system is ever started, and making an empty ParticleSystem.Particle[] array, then calling ParticleSystem.SetTrails() and ParticleSystem.SetParticles()

    The "ribbon count" parameter would not help as there would still be a ribbon connecting old, dead particles to newly-created ones.
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    StopEmittingAndClear really ought to work. This sounds like a bug. If you can send a report with a repro project attached we will look at it :)

    EDIT: if you want old bullet ribbons to remain, (ie not a full reset) you would have to use trails instead of ribbons, with a sub emitter and the Split SubEmitter Trails option. I think it could work.. basically one system for all bullets and one sub emitter for all trails..
     
    Last edited: Jul 23, 2020
    karl_jones likes this.
  3. Derakon

    Derakon

    Joined:
    Jul 3, 2019
    Posts:
    20
    After a great deal of debugging, this turns out to have been a false alarm. StopEmittingAndClear does indeed work.

    The underlying issue is that when I spawn a new projectile, I don't actually draw it for a few frames, to give it time to get clear of the gun that launches it. This caused it to short-circuit the logic that updates the emitter to track the projectile. However, the emitter was Played when the projectile was launched, so it was sitting off in some random location (wherever it'd been left by the last live projectile), emitting particles. Once the new projectile was old enough to draw, the emitter got snapped into place, and would dutifully draw ribbons between its particles as it did so.
     
    karl_jones and richardkettlewell like this.