Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Is it possible to alter Particle System Trail parameters from a trigger collider?

Discussion in 'General Graphics' started by keganheiss, Jul 30, 2020.

  1. keganheiss

    keganheiss

    Joined:
    Jun 23, 2017
    Posts:
    7
    Hi all! I'm trying to create an effect where a particle system becomes transparent where it intersects with a transparent object. I've been successful in getting the particles to become transparent by changing their alpha with a script connected to the particle system's Trigger module. My script for this is a barely-modified version of the example script in the Unity docs for the Trigger module:

    https://docs.unity3d.com/Manual/PartSysTriggersModule.html

    I am using the Trails Module. Trails do not seem to inherit the particle's parameter changes when hitting the relevant trigger collider.

    Is it possible to access Trail parameters on a per-particle (or per-trail) basis the way you can access individual particles?
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    Hi, no it's currently not possible.

    We recently exposed an API (2020.2) to Get and Set the trail data, for recording purposes (to store keyframes of a particle system state) but it has no interface for getting and setting the trail data for each particle.

    Right now we have:
    ParticleSystem.Trails trailData = ps.GetTrails();
    And:
    ps.SetTrails(trailData);

    But trailData has no methods on it.

    Each trail only stores a list of positions + alive times internally. Colors are based on the owning particle color combined with the gradient properties in the trail module inspector.

    So I guess all we could add would be ParticleSystem.Trails.GetPositions(int particleIndex) and ParticleSystem.Trails.SetPositions(int particleIndex, Vector3 position).

    And maybe something for the time value too...

    Is any of this sounding useful, if we added it? Do you know what kinds of API functions you would want?
     
  3. keganheiss

    keganheiss

    Joined:
    Jun 23, 2017
    Posts:
    7
    Thanks! That very fully answers my question.

    In my case I was hoping to access the trail's color, specifically its alpha channel when it's owning particle hit a trigger identified in the Trigger module. I could imagine having full access to the trail's parameters on a per-trail basis could open up a variety of possibilities, but it seems like access to size and color parameters would be the most useful.

    Since the trail can inherit color from the owning particle, is there or could there be a way to 'refresh' this inheritance when the owning particle's color is changed, specifically when interacting with a trigger?
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    It should auto-refresh I.e. it’s not stored, it gets looked up each time.

    Just change the particle startColor, and make sure the checkbox is enabled in the trail module to tell it to use the particle color.
     
    keganheiss likes this.
  5. keganheiss

    keganheiss

    Joined:
    Jun 23, 2017
    Posts:
    7
    Hmm... I haven't been able to get the trails to change color after they've been initiated based on the particle's changes, maybe I don't have things configured correctly?

    I've created a public minimal repro at:

    https://github.com/whisconierhillgames/ParticleStreamIntersectionTest

    The default scene is currently set up with a single particle stream passing through a box collider. The collider is assigned in the particle system's Trigger module to callback on enter and exit events. The script attached to the particle system successfully changes the alpha channel of the particle from solid to transparent and back again on the enter and exit callbacks. The trails, however, are unaffected by these events. The Trails module has the 'Inherit Particle Color' setting checked.
     
    Last edited: Jul 31, 2020
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    It's working for me. I made the cone shape really big so i could see the trails vanishing at the same time the particles vanished.

    With your narrow cone it's really hard to see them disappear because so many overlap.

    EDIT: I also ran a second test where I changed the script to use solid red, to make it even more obvious: Color32(255,0,0,255)
     
    Last edited: Aug 3, 2020
  7. keganheiss

    keganheiss

    Joined:
    Jun 23, 2017
    Posts:
    7
    Awesome, I wasn't looking at it right o_O. It looks like to get the effect I'm after I need to adjust some of my trail parameters. Thanks so much!
     
    richardkettlewell likes this.
  8. Mark_Hong_IGG

    Mark_Hong_IGG

    Joined:
    Nov 13, 2018
    Posts:
    2
    is there a function like TrailRenderer.GetPositions(Vector3[] position) for Particle System trails ?
     
  9. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    Hi, no, we don’t have anything like that currently.
     
  10. Malveka

    Malveka

    Joined:
    Nov 6, 2009
    Posts:
    191
    This sounds promising! Is there any chance we could get a method to toggle trail generation on/off for a given particle? I am this minute (once more) struggling with the issue of wanting to relocate a particle on birth when trails are turned on and getting the nasty "trail spike" as the particle is moved to its desired location.

    The only way I know to solve this problem currently is to use the particle system Emit method to make sure the particle is emitted at the target location, but this means one can't take advantage of the built-in Emission module and sometimes this issue comes up when working with assets from the Asset Store, etc.

    If trail generation for a given particle could be turned off until it reaches its actual desired start position (e.g. on a spline curve, as in attached screen capture), this issue (and I daresay many others) becomes easier to solve.
     

    Attached Files:

  11. SheepWings

    SheepWings

    Joined:
    May 26, 2020
    Posts:
    4
    Hi Richard,


    I'm currently working on a rewind game.
    And i wanna to rewind the particle system. Using Unity 2020.1.11f1c1.

    I'm using a list to store playbackstate trails and particles when fixedupdate.
    However, the particles is able to rewind correctly, but the trails are missing. In inspector, trial is still enabled and i tried to disable and enable it again, the trails are still missing.

    I also tried with unity 2019.3.1f1. Same result.
    I saw your reply in the forum about the particle systems.
    Please help.
    Thank you.
     
  12. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    Hi, it’s potentially a bug, I advise reporting it and we will investigate.

    One thing I would try before that though is to swap the order of SetParticles and SetTrails. Just in case :)
     
  13. SheepWings

    SheepWings

    Joined:
    May 26, 2020
    Posts:
    4
    Thanks for your reply. Swap the order does not help. I have reported it through unity. The case number is 1291267.
     
    richardkettlewell likes this.