Painting on the terrain ingame.

I was wondering if there is a way to paint on the terrain in game? Im trying to make a tank leave tracks behind but my current way is quite laggy (spawning tracks under me) is there any way to edit the terrains textures in game or edit a meshes?

Your best bet would probably be a decal system that "paints" on top of the terrain. There is a demo decal system available within the Unity Asset Store and you could make your own. If you are looking to make your own, all you need to do is spawn a texture at the point of collision between the tank's tracks and the ground.

You can paint on the terrain in-game using GetAlphaMaps and SetAlphaMaps, though that may not work well for tank tracks considering resolution issues, as well as not having directional information in the texture (i.e., the orientation of the texture is always the same).