Unity trail rendering done right: Ara Trails

Please, welcome our latest Unity asset: Ara Trails!

 

 

When and Why?

It had been sitting around as part of one of our larger projects for a long time, where we used it for a variety of purposes: line rendering, object trails, and smoke. We developed it out of necessity, since Unity’s standard trail renderer was not flexible enough to fit the bill in many cases.

After learning about how people struggled with trail rendering in Unity, we realized Ara (maori for “trail” or “path“, an homage to our kiwi experience not long ago) was probably too useful to be kept in our vaults.

How does it work?

Internally, Ara has many similarities to a traditional particle system like the one used by our Obi assets. Particles have position, orientation, color, thickness, and several other attributes that can be used to control all aspects of the trail. These can also be programmatically manipulated using your own scripts.

 

 

We will try to highlight a few features here:

Easy enabling/disabling

If you ever tried to simply disable trail emission temporarily you know it is not a trivial (or even easy) thing to do in Unity: Getting the already emitted trail to stay in place instead of disappearing when you disable it requires way more effort than it should be necessary.

Ara however allows you to control emission using a simple toggle (yay!). And you can gradually reduce the trail thickness/transparency, then bring them back up using curves for best results.

We used a small custom script (included with the asset) to perform raycasts under a car’s wheels and enable/disable trail emission depending on whether they hit the floor or not. It makes for some nice, low-effort tire marks:

Smooth trails

Since games use a discrete representation of time (basically they take a snapshot of the world every few milliseconds), fast moving objects tend to leave a choppy trail behind them. Weapon trails are specially affected by this. Ara uses Catmull-Rom spline interpolation to smooth out the trails, and they look so much better.

Left, a regular trail. Right, a smooth Ara trail.


High quality corners

In low-res trails, corners tend to look squashed and just plain ugly. We call this the “drinking straw” artifact:

Ara uses a high-quality mesh generation algorithm that can deliver truly sharp, constant thickness corners as well as rounded out and blunt ones. This is invaluable both for trails and line rendering.

 

sharp corners

smooth corners


Physics

Since trails are essentially a list of particles, adding a simple position-based physics system was a no-brainer. You can spice up your trails using gravity, velocity damping and inertia at virtually zero performance cost.

Scriptable

Ara allows you to post-process the existing trail particles after every frame, or provide your own list of particles. Using this you can:

  • precisely control where and when should new trail particles be emitted.
  • destroy existing trail particles.
  • place points anywhere to render lines.
  • change trail color, thickness, orientation or any other attribute using custom logic.

Here’s a typical scenario that is not easily achieved without the ability to script trail behavior: lightcycle-like trails.

In this case, we scripted trail emission to ensure new segments were emitted only when the player moves to a new cell in the grid. Trail color was mapped to movement direction:

// emit a new point every time we move to new coordinates.
if (Input.GetKey(KeyCode.W)){
    trail.initialColor = orange;
    trail.EmitPoint(pos);
}else
if (Input.GetKey(KeyCode.S)){ 
    trail.initialColor = red;
    trail.EmitPoint(pos);
}else
if (Input.GetKey(KeyCode.A)){
    trail.initialColor = blue;
    trail.EmitPoint(pos);
}else
if (Input.GetKey(KeyCode.D)){
    trail.initialColor = green;
    trail.EmitPoint(pos);
}

We also imposed a maximum trail length, expressed in cells:

// Remove excess points once weve reached the limit:
int excess = Mathf.Max(0,trail.points.Count-maxTrailLenght);
if (excess > 0){
    trail.points.RemoveRange(0,excess);
}

Overall we feel Ara is a great alternative to Unity’s built-in trail renderer.

  • Zero-memory allocation per frame has been achieved, so performance is excellent.
  • Both local space and world space emission modes are supported.
  • It is very versatile and easy to use both for artists and coders.
  • Runs in all platforms and the full C# source is included.

 

If you need a flexible solution for trails in your game, we’re confident enough to say this is the one and only solution you will ever need. 🙂

 

If you like it, please follow our next link if you want to check it out to help us even more!

 

 

Thanks everybody for your support!

5 comments

  • Awesome system!!

    Does your trail system support UI Trails at all? I really want to use trails to trace the edge of buttons and panels but amazingly getting Unity’s renderer to work above the UI seems impossible.

    Any help would be appreciated.
    Thanks.

  • Do these trails have collides or can collides be added?

  • Hi, I just bought ARA Trails and was not able to get acceptable performance.
    My usage is special in that I want 700 trails rendering at the same time. The unity trail renderer seems to handle this in VR an allows me to keep 100 fps. When I tried the ARA Trails, in the most basic setup, I have 12fps!
    Can you demonstrate or tell me how to run many ara trails at the same time!

    Thanks
    Dan

  • “Zero-memory allocation per frame has been achieved, so performance is excellent.” It’s awfully naive to think that memory allocation is the only thing affecting performance.

Leave a Reply

Your email address will not be published. Required fields are marked *