Trail renderer creates a trail on reactivation!

A Trail Renderer draws a line between its last active position and its current position on re-activation.

This bug only occurs if the Trail would still be drawn had you not turned off the Trail (set a long lifetime on the trail to make the bug occur).

To reproduce the bug:

  • create a trail renderer and set its time to 20
  • move the trail some, then disable the trail renderer component or its gameobject
  • move the trail some more, then re-enable the component or gameobject
  • observe that the line suddenly reappears, additionally a line is now drawn between the point where you disabled the trail and re-enabled it.

5871955--625132--EHT1nxcMFe.gif

This bug can be avoided by calling: TrailRenderer.Clear() in OnDisable.

This has to be a bug, right?

2 Likes

What would you expect to happen? For the trail points to be removed when it is disabled?
I guess what is happening, is that the trail enters a kind of ā€œpausedā€ state while it is disabled.

I doubt we will want to change this, given that you can easily use Clear … there is a risk of breaking other users’ content.

1 Like

Yes the points should be removed when it’s disabled, this is what happens in a particle system with trails gets disabled for example.

It’s not exactly behaving like a pause because if you set a short Lifetime: say 3s, make it draw then quicky disable it:

  • If you reactivate the trail after more than 3 seconds, you won’t have any points drawn.
  • If you reactivate the trail before 3 seconds have passed, then you will have points drawn.

I saw this bug when using a pooling system on fx with trails.

Yes, I expected this, not a problem :slight_smile:

It’s as simple as adding this script to fix the issue anyway:

using UnityEngine;

[RequireComponent(typeof(TrailRenderer))]
public class TrailRenderer_ClearOnDisable : MonoBehaviour
{
    void OnDisable()
    {
        var trail = GetComponent<TrailRenderer>();
        trail.Clear();
    }
}

To be clear: I don’t need anything changed, the question below is just me being curious.

Is there really no way to make new default behaviours for future versions without breaking user content?

5 Likes

There are ways to change behaviour for new content, but it can get weird and messy (imagine having a mix of upgraded vs new assets…)

If particles get cleared out when disabling the component, Im more inclined to agree with you about it being a bug… still scared to change it tho :wink:

I guess when it’s unpaused any points that would have died due to too much time passing will be all removed instantly when enabled. That seems like a more clear cut bug. If disabling doesn’t clear out the points then time shouldn’t pass for the trail while disabled either.

1 Like

does trail.clear() actually work?

It does absolutely nothing for me. Do you need to do this in a specific way?

never mind… figured it out. I was setting a position as soon as cleared it. I had to set the position first, then clear it.

2 Likes

including a ā€˜clearOn’ operation in the component with a ā€˜onDisable’ or ā€˜onActivation’ could allow users options; without causing existing content to have it enabled.

typically in pooling logic I have had to ask engineers to instantiate + move, then next update tic to activate… otherwise behavior can cause long streaks across game content, including the inherintVelocity on shuriken making particles wiz across the screen on the frame they awaken

3 Likes

this was my case too, it was coming from a pool.

I’m seeing a similar issue but slightly different. When moving the PS, some of the particles jump to the new location, then back and continue their remaining journey, creating a streak. It only happens in world simulation mode, and it doesn’t matter how the trail is set (World checked or unchecked).