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:
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?
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?
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?
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:
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.
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.
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.
There’s a bug with Get/SetTrails and Particles when the trails module “Die with particles” is off. In that case, when a particle dies, the trail will break and wrongly go from/to wrong positions, doing those spikes.
Code to test this behaviour, attach to a particle system which uses trails and has “Die with particles” disabled. There may be more bugs aside from that one.
// Put all this inside LateUpdate
var ps = GetComponent<ParticleSystem>();
var particles = new ParticleSystem.Particle[ps.main.maxParticles];
var particlesCount = ps.GetParticles(particles);
var trails = ps.GetTrails();
var playbackState = ps.GetPlaybackState();
// Test. Doing this must result in no visual changes, but after a particle dies, spikes will appear on the trails
ps.Clear();
ps.SetPlaybackState(playbackState);
ps.SetParticles(particles, particlesCount);
ps.SetTrails(trails);
EDIT: I’m filling a bug report, making it as simple as possible.
EDIT 2: Done, here’s the case number: IN-67806
And the attached video on the bug report that shows the problem:
Thanks for the feedback! Honestly, it’s unlikely as we are just doing important bugfixes for this system, and not new features. New feature work is all going into the Visual Effect Graph package.