Im trying to make a world consisting of cubes and ramps to represent terrain how can I do this on a large scale with out sacrificing performance? I've tryed the built in mesh combiner and that helped a little. I'm also using the lowest texture size possible.
use a rectangular object array. you may have to take some time to sort through all of the gobbledegook and figure out how to declare the array if you’re using an older version of unity, but once the array is declared, you can set each of your terrain objects as a variable. assign your prefabs to the variables through the inspector, and then you can define the array grid. after defining the array grid, instantiate it procedurally. the performance benefit here is that each object is pre-loaded into memory by assigning it to a variable, and the entire terrain is handled as a single variable, regardless of the number of objects. also, in addition to using the smaller texture size, use the SAME texture for each object, or at least for as many as possible. my example is a 10 X 10, but I’m not gonna write it all. most of the code is just redundant copy-paste-define. the code would look something like this :
var maxX : int = 10;
var maxZ : int = 10;
var objectWidth : float = 10.02;
var objectLength : float = 11.23223;
you will have to play around with the object widths and lengths until they are just right. I HIGHLY recommend you make
all of your terrain features be based on a common rectangular size. Square is even better. If they aren’t, you won’t be
able to use the for loops to instantiate them, and will have to manually instantiate each one, leaving you with poor
performance, and a disgustingly long script. D-8
var ramp : GameObject;
var hill : GameObject;
var valley : GameObject;
var flat : GameObject;
drag prefabs to the above slots in the inspector to define the terrain features.
var terra : GameObject[10,10];
terra[0,0] = flat;
terra[0,1] = hill;
terra[0,2] = valley;
//...
terra[9,7] = ramp;
terra[9,8] = valley;
terra[9,9] = flat;
//...
…etc, etc, etc, ad infinatum, ad nauseum. Sadly, you will actually have to go through and manually declare each spot on
the grid this way. However, once they are all declared you can instantiate them in a FOR loop within a FOR loop…
also keep in mind that if you change the maxX and maxY values (i.e. the size of the grid), you will have to add lines
of code accordingly.
function Awake() {
for (var i=0;i<maxX;i++) {
for (var j=0;j<maxZ;j++) {
Instantiate (terra[i,j], Vector3(i * objectWidth, 0, j * objectLength), Quaternion.identity);}
}
}
this will cause some loading time at startup, so be prepared for that. another benefit of this method is that you can redefine the
entire terrain whenever it changes, such as raising or lowering terrain in a populous type game environment, where the player
modifies the terrain to achieve a desired effect. you can redefine it by changing the “function Awake()” to “function Redefine()”, and calling the redefine function whenever the terrain changes. it would be better to redefine only the specific block that changed, however, but that requires you to play around with unique instance i.d.s and grid locations, blah blah blah, but I’ll leave you to figure that one out.
good luck with your populous remake. X-D