I'm making a test for a game with 2D gameplay, sidescroller. I need to make an endless ground moving from right to left and the character will be always running in the centre of the screen. The ground is composed of 4 simple different elements which need to tile randomly.
What I did: Made a prefab to instantiate out of the right side of the view. When one instantiates, it randomly picks it's own mesh. When it moves for the length of the element, another one instantiates and so on. After the instance exits the camera view, it self-destroys.
it's elegant and works fine on my strong PC but I wonder if it would be better, performance wise, to instantiate them all at the start of the game, somewhere out of view and just move them when needed. Without destroying them but rather make them wait their next turn. I would need 12 or more instances because sometimes I will have 2 or 3 same meshes in the view.
Which method is more performance friendly? "Instantiate on the fly" or "Instantiate all at start and then transform"?
asked Feb 07 '11 at 02:48 PM
Generally speaking, reusing existing game objects will likely be faster. (Whether it matters or not will of course depend on the context.)
answered Feb 08 '11 at 02:01 AM