#Change Particle Trail Color Within Region

1 messages · Page 1 of 1 (latest)

pearl nexus
#

Hello! I've been researching this for a while with no luck. It seems like a simple ask, but I just can't seem to figure it out nor find anything online for what I am aiming for.

I have a very simple particle system emitting a bunch of particles from a point that all leave behind white trails. Upon having these particles enter a certain defined region (trigger, or whatever) I would like to have the part of their trails within the region change color.

For reference, something like the attached image. Any ideas? Thanks!

pearl nexus
#

Change Particle Trail Color Within Region

wild pumice
#

I haven't really worked with particles, but I think this may be what you're looking for: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html

As the documentation states, this callback is invoked if the gameobject the script is attached to contains a Particle System and it hits a collider. (What I'm not sure is if the collider can be marked as trigger)

What I'm also not sure is if does this work with the VFX Graph package, since you haven't stated which one are you using. If it doesn't work, I'm not sure if you could handle what you want to archive with GPU events.

little lily
#

You could use a custom srp render pass to get this done

pearl nexus
#

Thanks for the replies guys. @wild pumice I think the issue which changing the trail color on collision is that the entire trail color will change, not just the part within the region. (Just a guess as I tried something similar to this when I was using trail renderer before I started exploring the particle system.) I haven’t tried with the particle system though so I’ll give it a shot.

@little lily sounds more advanced than I have worked with. Will look into this. Thanks!

wild pumice
#

Udula's solution sounds more like the way to go to me as well, but at the same time more complex (I have never worked with shaders/custom srps)

Btw in case you don't manage to do it with a srp, there might be a workaround, not really elegant tho. Create an empty particle system with a trail of the other color you desire, and when entering/exiting that certain area, switch the trail sizes. I haven't tested it but it might work.

But again, I'm not really a fan of this solution since 2 trail renderers shouldn't be needed, so I encourage you to try and solve this issue with a custom srp.

little lily
#

@wild pumice and @pearl nexus If you want to this articles are a get place to start and it's a very useful skill to have imo

#

also unity likes to break old srp code every time they update it so you might have to swap out some keywords with their newer versions

wild pumice
#

Thank you very much for sharing, I'll give it a look once I get home!

pearl nexus
#

@wild pumice I actually did something like this before when I used my trail renderer implementation that didn’t involve the particle system. Basically, I had two trail renderer components, and I would just swap between the two on collision. It worked but I knew there was a better way! @little lily thanks for the resource. I started watching a video on this last night, but got confused pretty quickly. I think I need to dedicate some time to learn this outside of my current project then hop back in and try to apply it.

wild pumice
#

I agree, it's always good to take a break to learn something new. Best of luck learning about this topic!

little lily