Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 wijesijp · Oct 24, 2013 at 10:43 AM · trailrenderer

How to disable trail renderer

I add trail renderer for my bullet. I am also using object pooling. When I reuse by bullet the trail renderer draw all over the screen.

I tried enable and disable but it does not work.

Is there a way to disable trail renderer?

Comment
Add comment · Show 1
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 bjoerninger · Feb 05, 2017 at 05:47 PM 0
Share

so, did you fix your problem? got the same atm, trailrenderer does not seem to react to scripts

6 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by Junglej0hn · Dec 07, 2017 at 01:26 PM

To anyone who still has this problem in 2017. Use myTrailRenderer.Clear()

Comment
Add comment · Show 2 · 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 MrJamieMcC · Feb 14, 2018 at 10:52 PM 0
Share

Thank you so much! I was having issues with this trying to disabled then re-enable the renderer.

Thanks very much

avatar image krupasknr · Feb 26, 2021 at 02:02 PM 0
Share

Thanks man,, it works

avatar image
0

Answer by sethuraj · Oct 24, 2013 at 12:13 PM

When you reuse the bullet set

 gameObject.GetComponent<TrailRenderer>().enabled=false; 


to disable the trail render.And on firing the bullet, set it to true.

Comment
Add comment · Show 3 · 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 wijesijp · Oct 24, 2013 at 12:47 PM 0
Share

I tried it but it does not work

avatar image sethuraj · Oct 24, 2013 at 02:17 PM 0
Share

it will work.make sure you are calling this in a script which is attached to a gameobject that has Trail Render.If still its not working,please show your code so that we can diagnose properly.

avatar image krupasknr · Feb 26, 2021 at 02:02 PM 0
Share

use trailrenderer.clear()

avatar image
0

Answer by wijesijp · Oct 24, 2013 at 04:43 PM

The code I have so far. I wrote it by checking out someof the posts in the site. It look OK most of the time. But sometimes it does not work

     private TrailRenderer line;
     private float _trailTimer = 0.1f;
     private bool alive = true;
 
     private Vector3 movingDirection;
 
     void Awake()
     {
         line = gameObject.GetComponent<TrailRenderer>();
         line.time = -1;
     }
 
     // Use this for initialization
     public virtual void Start()
     {
        
         gameObject.renderer.enabled = false;
         trans = gameObject.transform;
         spentLife = lifeTime;
 
     }
 
     public virtual void Init(CreepAI target, Vector3 startPosition, float damageAmount, float areaOfEffect, string damageCauser)
     {
        
         this.damageAmount = damageAmount;
         this.areaOfEffect = areaOfEffect;
         this.damageCauser = damageCauser;
 
         movingDirection = Vector3.Normalize(target.gameObject.transform.position - gameObject.transform.position);
 
         
 
     }
 
    
     // Update is called once per frame
     protected virtual void FixedUpdate()
     {
        
 
         if (line.time <= 0.0f)
         {
             _trailTimer -= Time.fixedDeltaTime;
             if (_trailTimer <= 0)
             {
                 gameObject.renderer.enabled = true;
                 line.time = 0.50f;
                 _trailTimer = 0.1f;
             }
         }
 
         trans.position += movingDirection * Time.fixedDeltaTime * speed;
 
        
         spentLife -= Time.fixedDeltaTime;
 
         if (spentLife <= 0.0f)
         {
             line.time = -1;
             ObjectPoolManager.DestroyPooled(gameObject);
         }
 
 
 
     }
 
     void OnTriggerEnter(Collider other)
     {
         line.time = -1;
         DestroyProjectile();
 
 
     }
 
     public virtual void DestroyProjectile()
     {
         gameObject.renderer.enabled = false;
         ObjectPoolManager.DestroyPooled(gameObject);
 
         
     }
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 QuintenVTW · Aug 17, 2017 at 11:24 AM

I've got a similar issue.. I'm making a game with a rolling ball for android. And in this game is a teleporter, but every time if the ball (the ball has a trail) passes trough the teleporter you can see the trail going from teleport pad A to pad B .. very annoying. I tried to stop it but it did not work out.

public void OnTriggerEnter(Collider other) { other.GetComponent<TrailRenderer>().enabled = false; other.transform.position = Destination.transform.position; other.transform.rotation = Destination.transform.rotation; other.GetComponent<TrailRenderer>().enabled = true; }

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 QuintenVTW · Aug 17, 2017 at 11:25 AM 0
Share

Im not sure how to add code properly.. sorry!

avatar image
0

Answer by Humman · Feb 18, 2018 at 01:20 AM

Its simple, put Trail render component in empty node under object with trail and use gameObject.setActive() for this child node

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 StringAtlas · Dec 22, 2021 at 01:56 AM 0
Share

that doesnt work since the trail is still there after you setActive(True)

  • 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

24 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 avatar image

Related Questions

Trail after game object with pause/clear function 2 Answers

TrailRenderer sorting layer problem. 2 Answers

Creating an infinite trail that can be collided with 2 Answers

Is possible to save a trail rendered to load again after? 1 Answer

How to get Zerg Tentacle-like effect (see example in post)? 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