x


Instantiate VS Transform

Hi,

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"?

Thanx, Vlad

more ▼

asked Feb 07 '11 at 02:48 PM

uberwleiss gravatar image

uberwleiss
198 10 14 22

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Generally speaking, reusing existing game objects will likely be faster. (Whether it matters or not will of course depend on the context.)

more ▼

answered Feb 08 '11 at 02:01 AM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1726
x1335
x680
x517

asked: Feb 07 '11 at 02:48 PM

Seen: 1044 times

Last Updated: Feb 07 '11 at 02:48 PM