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
1
Question by Andre-Odendaal · Jan 09, 2011 at 10:37 AM · trailrenderer

Remove all particles from TrailRenderer

I'm implementing a sword mechanic and I'm using a trailrenderer to show the swish which is enabled (by setting the time to a value) when the left-mouse is down and disabled when mouse up.

However, if the player makes the next swing quickly, the trail jumps to the start position and creates a connected line.

I would like to clear all the particles for the next swing but TrailRenderer.ParticleEmitter.ClearParticles() doesn't seem to work.

How can I immediately clear all the particles for the next swing?

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

6 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Aubrey Hesselgren · Aug 16, 2011 at 03:05 PM

I'd love to know for something similar: I have an object which is on a wrap-around map, and crossing the "seam" (repositioning the player by one world-unit) looks glitchy, leaving behind a big streak because I don't know how to access the trail points directly.

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 testure · Aug 16, 2011 at 03:41 PM

you can set the length of the trail to zero, and then restore it when you want it to reset, but this is the only way to do it short of destroying the trail renderer and recreating it each time.

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 sampenguin · May 10, 2012 at 07:33 PM

I just solved this similar problem by creating instances of the trail renderer from a referenced prefab, and then destroying the instance at the points in time when I need an absolute clean visual break in the trail (and of course, creating a new instance for the next trail). It's a bit of code overhead but the only way I could come up with something that worked after a day of trying everything else.

In your sword example, I would suggest you allow for something like an array/list of swings, where each swing Instantiate()s its own new trail that can fade to completion correctly, and then destroy itself after all fx complete.

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 Wabo · Feb 20, 2013 at 09:14 PM

 What worked for me is this:
 
 //Declare your temporary timer.
 private float _trailTimer = 0.1f;
 
 void YourFunction()
 {
      this.gameObject.GetComponentInChildren<TrailRenderer>().time = 0f; //Disable the Trail Renderer.
 }
 
 void Update()
 {
         //Reset the trail of the TrailRenderer so that it wont glitch through the 
         //screen while pooling the object.
         if(this.gameObject.GetComponentInChildren<TrailRenderer>().time == 0)
         {
             _trailTimer -= 1 * Time.deltaTime;
             if(_trailTimer <= 0)
             {
                 this.gameObject.GetComponentInChildren<TrailRenderer>().time = 1.5f;
                 _trailTimer = 0.1f;
             }
         }
 }
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 atreyuroc · Jul 04, 2018 at 09:05 PM

I know this is an old post, but I hope this solution can help someone.

The work around I found for this issue was to set the TrailRenderer.time to negative one. This will ensure that any existing trails are removed. But you can not reset the trail time back to the default value at the same time. For some reason you have to let unity process the -1 for a frame or two.

Here is some example code.

 public class Ball : MonoBehaviour {

     private TrailRenderer tr;

     // Use this to hold what ever the current time might be.
     private float trailTime;

     void Start(){
         tr = GetComponent<TrailRenderer>();
     }
 
     private void ResetTrailTime()
     {
         tr.time = trailTime;
     }
 
     public void ResetTrail()
     {
         // Save the old time
         trailTime = tr.time;

         // Set to -1
         tr.time = -1;

         // Wait some frames and then set the trail time back. 
         Invoke("ResetTrailTime", 0.001f);
     }

 }
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
  • 1
  • 2
  • ›

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

6 People are following this question.

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

Related Questions

TrailRenderer causing crash in gleRunVertexSubmitARM- what's that? 0 Answers

not able to disable trail renderer 2 Answers

Custom trail fixed length and custom form 1 Answer

How to get a glow/lightning trail effect 1 Answer

Assign Edge Collider Points to Trail Renderer Vertices 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