"Destroy" bullet without turning off trail renderer

SO I’ve got a game where you shoot bullets at other players in slow motion. You can deflect bullets with other bullets much like in the movie “Wanted”. To help communicate to the player where the bullets are I put some trails on them. However, if I destroy the game object the trails disappear.

I created this script that checks the collision with the wall, instantiates a bullet hole on the wall, and then turns off the mesh renderer & mesh collider. However when I shoot a wall the collider does not shut off until after it has collided so I end up with invisible trails bouncing to the ground.

Any Suggestions?

Here’s the code

void OnCollisionEnter(Collision collision)
		if(collision.gameObject.name == "Wall")
			// Make sure the shot has made contact
			Debug.LogWarning("Collided with wall");

			// Find the contact point so we can instantiate the Bullet hole facing the player
			ContactPoint contact = collision.contacts[0];
			Quaternion rot = Quaternion.FromToRotation(Vector3.down, contact.normal);
			Vector3 pos = contact.point;

			// Create the Bullet hole facing the player
			Instantiate(bulletHole, pos, rot);

			// Destroy the bullet WITHOUT turning off the trail renderer
			renderer.enabled = false;
			collider.enabled = false;
			Destroy(gameObject, 5);

What you wanna do is to predict if the bullet will hit the wall.
You can do that by raycasting forward from the bullet, and if the ray hits a wall say, 0.1 units away, the collider is turned off.

I can give you an example later when I get home.

That can find the docs for raycasting here: Unity - Scripting API: Physics.Raycast

private Vector3 prevPos = Vector3.zero;
private RaycastHit hit;

private bool CheckCollision(){
   if(prevPos == Vector3.zero){
      prevPos = transform.position;
      return false;
   return Physics.Linecast(prevPos, transform.position, out hit);

Then you can do:


This is keeping track of previous position and creating a line between the previous and the current position. If something in between you get it.