7
\$\begingroup\$

Ok, question.

I've been fiddling for Unity for a while and now trying to make a cohesive game.

Up until now I've found the quickest way to design levels for me is to create a block of wall/floor to work as a "unit", and copy it lots of times.

The result is something like this enter image description here

The blocks are basically just a transform + a sprite renderer + a box collider.

Now my question is: Can this approach bring problems given that it basically creates lots and lots of objects? If so what alternatives there are? Creating bigger blocks?

\$\endgroup\$
2
  • 5
    \$\begingroup\$ Profile, profile, profile... Create 10x as many objects as you think your biggest level will be then test it. If there is a problem then, address it. No problem? Then why would you create extra work for yourself. \$\endgroup\$ – ADB Sep 7 '15 at 20:39
  • 1
    \$\begingroup\$ ADB's comment should be the accepted answer. Solving performance issues that don't exist yet is in a lot of cases a waste of time. \$\endgroup\$ – Patrick Klug Sep 10 '15 at 21:37
12
\$\begingroup\$

Yes, creating lots of objects can create performance problems down the road. The alternative is using fewer objects. In this case, fewer objects taking up the same amount of space means larger objects.

You can, for example, create a texture that looks like 4 or 8 blocks side by side, then create one object that's 4 or 8 times longer than a regular block.

\$\endgroup\$
6
\$\begingroup\$

A good way to do this would be to have a game object that generates the blocks from a script, then generate a box collider for the whole thing and render it all from one game object. That would remove the need for a huge amount of game objects. All you would need to do from there is pass the map-generator some sort of block-map.

Of course, any unique blocks that could be uncommon within the game can be kept as separate units.

\$\endgroup\$
1
\$\begingroup\$

If it's just 1 block, then you only need 1 prefab, and you could instantiate that prefab in a script, when needed, and of course apply a transformation to fit into the right position, or destroy if you no longer need them.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.