Programming techniques: Long rail type levels (seamless terrain)

I am currently thinking about the best way to load the terrain of a rail type shooter. Obviously placing all the terrain elements in the Editor is not the best approach.

I was thinking about generating new instances of terrain as we get close to the end of the current one.

public GameObject TerrainPrefab;
void AddTerrain(Vector3 pos)
{
	GameObject fire = (GameObject)Instantiate(TerrainPrefab, pos, Quaternion.identity);
}

But that causes small fps drops which might not be noticeable if you have an almost empty scene but it might cause lag spikes in the final game where every bit of performance important. Making it asynchronous would work but I dont know if thats even possible with Unity.

Second approach I could think of is only having 2 instances of terrain and after passing the previous one it gets moved after the current one and the new terrain gets loaded into the terrain data. But then again I am not sure if swapping the terrain data would essentially require the same amount of calculation as the first approach.

EDIT: Now I saw that Unity has a LoadLevelAdditivieAsync function but that is for the PRO version only which I cant afford yet. Actually I only need to load the terrain asynchronous.

I am fairly new to Unity and also in general to game development so I would like to get some opinions from experienced people.

What do you think? What might be the best approach? Is it possible to do it asynchronous in a new thread or something like that in Unity Free to counter lag spikes?

Have a look at this free Infinite Terrain project. There’s also the possibility to just move the player and its comforting space and relocating at the very origin point when the track runs out (instead of moving everything else, which is far more intense).

Unity runs all coroutines in a single thread where some features, already defined by the engine, is multi-threaded. You cannot tell Unity what to multi-thread. Although not to confuse with multitasking, which Unity is great at. For future versions of Unity (with v3.3 as current) more things will be capable of multi-threading. Version 3.5 will have a multi-threaded renderer for instance - which will take some load off of everything else.

Here’s some more information about infinite/seamless terrains:

http://answers.unity3d.com/questions/9633/possible-infinite-terrain-plane.html

http://answers.unity3d.com/questions/17225/dynamic-terrain-loading.html