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?