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 Arowx · Mar 01, 2011 at 12:36 PM · disabletrailrendererreuserecycle

Recycled trailers leave streaks...

How to reset the trail of a trail renderer so when I recycle and reactivate pooled objects they don't leave streaks?

I've tried turning off the TrailRenderer and ClearParitcles on the particle emmiter when they are reused but with no joy so far...

Example Bullets, 1 Created/Recycled sets position and rotation (reactivated) 2 Fired adds velocity 3 Stop/Explode 4 Deactivated - Velocity Zeroed 5 Pooled 6 Reused back to 1

Am I missing something, in effect I want to restart/reset the trail when I reactivate the object?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by turbanov · Feb 11, 2016 at 01:05 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
0

Answer by efge · Mar 01, 2011 at 01:38 PM

You should make a prefab for your bullet and add a TrailRenderer, use Instantiate to use your bullet and Destroy after collision or explosion. This activates and kills your TrailRenderer as desired.

See Also: In depth Prefab Instantiate discussion

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 Arowx · Mar 01, 2011 at 02:22 PM 0
Share

Cheers I was trying that without the prefab and it was getting messy having to set things by hand.

Using a prefab would work much better, but found a work around disable the trail then when the bullet is fired Invoke a function that will re-enable it with a delay from it's time property. It works but not sure it it would be better performance wise just to delete and recreate.

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 maesty · Oct 14, 2013 at 11:53 PM

function FixTrail() {

     var tr : TrailRenderer = GetComponent(TrailRenderer);
     var tmp : float = tr.time;
     tr.time = -1;
     yield;
     tr.time = tmp;
 }
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Trail renderer leaves streaks 0 Answers

How to disable script in MainCamera game object 1 Answer

image not enabling 0 Answers

How to disable an certain animation from my player? 0 Answers

Best animation plugin that works with the new 2D stuff? 0 Answers


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