Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DiligentGear · May 12, 2014 at 07:21 PM · resettrailrenderercleartrails

Is there anyway to reset/clear Trail Renderer?

Is there anyway to reset the Trail Renderer or clear the trail of Trail Renderer?

I'm currently using object pooling to avoid performance issue about run-time instantiation, but the trail renderer doesn't reset correctly -- it leaves streaks everytime it gets enabled.

I had searched a lot of answers and threads, the closest one is to set time to negative on disable, and wait a few frame to set it back. But this approach still won't work if the bullet runs faster.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by turbanov · Feb 11, 2016 at 01:06 PM

New Unity version has a Clear method for trails: http://docs.unity3d.com/ScriptReference/TrailRenderer.Clear.html

If this option is not available for you I recommend resetting the time in the OnRenderObject callback of your script:

     void OnRenderObject()
     {
         if (!float.IsNaN(_ClearTimeS))
         {
             _TrailRenderer.time = _ClearTimeS;
             _ClearTimeS = float.NaN;
         }
     }

     private float _ClearTimeS = float.NaN;

     public void Clear()
     {
         if (!float.IsNaN(_ClearTimeS)) return;
         _ClearTimeS = _TrailRenderer.time;
         _TrailRenderer.time = 0;
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by bitstrider · Aug 29, 2016 at 09:29 AM

GetComponent<TrailRenderer>().Clear()

handles this as of 5.3

https://docs.unity3d.com/530/Documentation/ScriptReference/TrailRenderer.Clear.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by tarahugger · Aug 24, 2014 at 09:36 PM

The following works for me to move a trailed object without it streaking.

Place this extension in a c# file somewhere in your assets folder.

 public static class TrainRendererExtensions
 {
     /// <summary>
     /// Reset the trail so it can be moved without streaking
     /// </summary>
     public static void Reset(this TrailRenderer trail, MonoBehaviour instance)
     {
         instance.StartCoroutine(ResetTrail(trail));   
     }
 
     /// <summary>
     /// Coroutine to reset a trail renderer trail
     /// </summary>
     /// <param name="trail"></param>
     /// <returns></returns>
     static IEnumerator ResetTrail(TrailRenderer trail)
     {
         var trailTime = trail.time;
         trail.time = 0;
         yield return 0;
         trail.time = trailTime;
     }        
 }

then use it from within a monobehavior like so

 trail.Reset(this);

see also

  • http://answers.unity3d.com/questions/50009/recycled-trailers-leave-streaks.html

  • http://forum.unity3d.com/threads/trailrenderer-reset.38927/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image atomicjoe · Feb 19, 2015 at 12:03 PM 0
Share

I had to change the yield at line 20 for this one to make it work:

 yield return new WaitForEndOfFrame();

This will work as long as you have a camera rendering your scene.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Right time for Move & Clear Pooled TrailRenderer 0 Answers

Collectibles Objects and Resetting game after all are collected in javascript? 1 Answer

Trail renderer not working 1 Answer

How to clear baked shadows? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges