I’m using a trail renderer with my projectiles, of which I dynamically pool. After the projectile has exceeded it’s range it is immediately set as inactive and waits to be triggered again. However when this happens there’s a split second where the trail renders from the position the projectile was laying dormant. I’ve tried several things, like disabling the trail renderer and re-enabling in the OnEnable() call. I’ve tried setting the TrailRenderer.time to 0f until the OnEnable call. None of that is doing the trick.
Let me know if I need to explain or detail anything else. It’s a super obnoxious effect and I hope I can get it resolved soon.
It didn’t work with OnEnable for me (probably because of how I set up my code) so I did it just when setting the bullet object to inactive (when it hits a target/ covers max range) and then it worked for me perfectly! Just in case this helps anyone. Thanks a lot for the response!
if (trailRenderer != null) trailRenderer.Clear();
gameObject.SetActive(false);
I know it’s a late answer. But for new people seeking for a solution to this unfortunate effect.
Instead of clearing trail effect on enable (When object being pooled from pool). Try clearing it on object Release() (When you return the pooled object to the pool).
void Awake() {
_trailRenderer = gameObject.GetComponent<TrailRenderer>();
}
void Release() {
/* Clear trail effect
* (Can add all effects to be reset or re-configured here)
*/
_trailRenderer?.Clear();
// Return object to pool in order to disable it and be ready for reuse
_pool.ReturnToPool(this);
}