A bit of background. I have a script that instances on start my desired number of gameobjects named grassplane. Grassplane is a quad with a texture for grass. The game is an endless sidescroller.
The result in itself is pretty good, visually speaking. I even created my own pooling system so they go back to the spawnpoint without any error. Well, it’s not even really pooling as in storing them anywhere, they just cycle endlessly instead of instance-destroy.
My problem comes with how much computing they need to move endlessly.
Each grassplane has the following code:
function Start () {
tr=transform;
}
function Update () {
speed = speed_logic.speed;
transform.Translate(-Vector3.right * speed * dir * Time.deltaTime);
posx=transform.position.x;
if (posx<bg_trees.endpoint){
spawnpoint=Random.Range(min,max);
posz=spawnpoint*step;
tr.position = Vector3((posx-bg_trees.endpoint)+bg_trees.startpoint, posy, posz);
//transform.position = Vector3((posx-bg_trees.endpoint)+bg_trees.startpoint, posy, posz);
}
}
The whole tr=transform comes from a certain tutorial that mentions that everytime i’m simply saying “transform” it uses getcomponent, which is an expensive call, but it feels like they result in the same performance actually.
I tried grouping many of the grassplanes so instead of calling 500 individual planes, I’d be calling 100 to a parent gameobject of 5 grassplanes, but from the profiler I draw the conclusion that it’s the same cost performance-wise.
Is there any way to make it less expensive?
Thanks in advance,
Ed