Combining sprites at runtime?

I’m experimenting with procedurally generated terrain. I just made my first terrain generator for a top-down 2D game, which instantiates chunks of 32x32 Game Objects (each one is a tile sprite) when the player gets close to unexplored areas.

This is obviously inefficient, (and also causes huge hiccups when chunks are being generated) so I’m trying to find a way to optimize this method. I know with meshes there are some workarounds, but I’m using sprites here.

Can I combine chunks of tiles at runtime somehow? Is there a better way? I’m certainly a noob in procedurally generated stuff.

Thanks in advance!

Having kind of the the same problem over here :slight_smile: … Have you found a solution for this in the meantime?

How many are you generating? Do they have alphas? Are you using a shared atlas? Do the tiles have any monobehaviors attached?

A project I am working on instantiates about 2,000 - 3,000 sprites on start with no delays or hiccups and only 2 drawcalls. Sprites are pretty light weight, it shouldn’t be causing performance issues if done right.

If you mean you are trying to figure out a way to combine different sprite files look into TexturePacker. It has a Unity plugin as well as a stand alone program to do this. The free version can do it.

The main problem is that you are using sprite renderers for tiled terrain. As zombiegorilla said is not a big problem if is in the same atlas, the problem is in the dynamic batching. Too many gameobjects to deal with, I had he same problems on the matter and switched compeltly on using meshes, I procedurally generate chunks of 16x16 tiles but still maintaining 1 gameobject per chunk.

I was reading somewhere in the forums, not sure was official but that the next update of unity will add ileable sprites, meaning you can tile one sprite as one gameobject.

Take a look here too:

http://forum.unity3d.com/threads/240750-2D-Efficiency-With-Sprites-and-Game-Objects

Also if you have an alpha channel, go under advanced in the texture and set the mesh type to “Full Rect”. That will have only two triangles per sprite.