I am working on a game which uses a 40 X 40 grid. Each cell in the grid is made up of GridCell objects.
And here is how I am initializing the grid currently,
As you can see I am initializing 1600 GameObjects here and this causes my load time to shoot up. Is there anyway I can optimize this initialization. It will be really helpful.
asked Aug 06 '10 at 12:42 AM
I had this same issue. As far as I could see if you have to create a gameobject then you have to create a gameobject and suffer the consequences. All I have to suggest is putting a yield statement in the inner or outer loop. This will stop your game 'freezing' as it loads but will have the appearance of creating the grid over a number of frames. You could however make this a 'feature' Of the start of the level to mitigate the issue. I.e. A sort of materialization of your grid fanning out from some point.
 you are calling Resources.load every object. Take that out of the loop and create a reference to it. Then instantiate via the reference.Also use the full constructor for instantiate to save a call to transform every iteration. Eg. Something like:
sorry about the formatting - tricky on the iPhone. Ps I code in jscript so may not be 100% syntactically correct.
make sure your grid has it's renderer enabled by default and remove the call that enables the rendere for each cell.