Basically what i want to do is to paint roads on terrain as my NPCs are moving. I manage to get this done, but when using
terrain.terrainData.SetAlphamaps(0, 0, splatmapData);
in conjunction with FixedUpdate or Update, the frame rate is going down to a crawling slide-show. I’ve tried to move it to a coroutine but it doesnt make any difference, i also tried to edit only one tile on the alphamap but with no success.
You can see the code here http://forum.unity3d.com/threads/108885-Modify-terrain-texture-at-runtime
P.S. I did an extensively search on this subject but couldn’t find anything related to my problem.
The terrain docs are too vague - no examples, no detailed explanations - but what I understood from them is that the dimensions of the array passed to SetAlphamaps(x, y, arrayOfFloats) define the size of the region to paint. If your array is too large, it will take a big time to update the terrain. Try the following: create a single element array, copy the new data to it (update your splatmapData array also, if you want) and pass the single terrain element to SetAlphamaps - something like this:
// I'm a JS guy, thus the code below may have horrible C# errors
float[,,] element = new float[1,1,2]; // create a temp 1x1x2 array
splatmapData[y, x, 0] = element[0, 0, 0] = 0; // set the element and
splatmapData[y, x, 1] = element[0, 0, 1] = 1; // update splatmapData
terrain.terrainData.SetAlphamaps(y, x, element); // update only the selected terrain element
...
You my friend are a genius 
I’ve tried something similar last night, but it seems i was too tired to notice that i created a
float[,,] element = new float[1,1,2];
with too many elements, I used
float[,] element = new float[x,y,2];
which in my case x and y was around 300 so there was no difference 
Cheers mate.
@penna91 Im using this code in a project im developing. But I get frame drops if i want to paint a larger area. I do it by duplicating the objects to which this script is attached to.This results in a huge drop in frames. From 40Fps to 6Fps. Can you tell me how to increase the area that im trying to paint?? So that this script is attached to a single object.