- Home /
Why is my 2D voxel game terribly unoptimized?
Up until recently, it has been fine. However I opened up the project today and I hit play, and it took about 12 seconds to run. The grid of tiles adds up to 16^2 8 16. However I've already generated it and I'm not regenerating it on start. In fact, none of the tiles are programmed to do anything upon start. I use a sprite material I made with pixel snap to render them. I just wonder if the population of my scene as of now is too large to run all at once. I even tried deactivating all my tiles and running, but no luck. Anyways hope this can get resolved. Thanks!
-Edit-
For some reason the scripts attached to each individual tile is what is causing this. Is there a way to optimize this, or should I make a manager that handles this stuff?
Are you using seperate GameObjects for each tile by any chance?
@Cherno i assume from your comment that there's another way to do this. Could you inform me on how others could possibly achieve these tiles?
For voxel-based environments, the common technique is create "chunks" by combining many individual meshes into one larger mesh.
Generally, it goes like this:
You have a two- or three-dimensional array, where each element hold information about the cell/tile at position x,y(,z). If, for example, you want to access the tile that the cursor is pointing at, you would convert the cursor position to world space and use it to get the x,y coordinates in your array. You create a mesh, or multiple meshes (chunks) by going through each tile of your array and create a plane or cube (or anything else) at the current x,y position.
There are dozens of tutorials for this, search for "procedural mesh generation" and similar terms.
Answer by Zoogyburger · Feb 12, 2016 at 10:00 PM
Why are there scripts attached to every different tile? Why not make all your tiles one game object by checking tiles as "static" I got a better performance.
You might want to try this program for tilesets:
and import the maps you make using
http://www.seanba.com/tiled2unity
to learn how to use this go to
https://www.youtube.com/watch?v=NNpLsimyu3I&list=PL_4rJ_acBNMH3SExL3yIOzaqj5IP5CJLC
Hey @Zoogyburger,
How could I possibly attach a script to something else rather than all the tiles? The tiles have to detect when they're broken, how else could I do it?
I don't need those programs I'm sure there's a way to do this. I just don't know how.
$$anonymous$$ake your tiles children of an empty gamobject add your script to it with this line of code:
void Start (){
foreach (Transform child in transform)
{
child.gameObject.AddComponent<scriptname>();
}
}
}
Your answer

Follow this Question
Related Questions
Sprite not visible from behind 0 Answers
My camera not rendering anything in Custom render type,I have an issue: 0 Answers
How do I make one light source override all other light sources? 0 Answers
How to Display Hundreds of Thousands of Sprites? 2 Answers
Mesh with vertices changed in script is not rendered 1 Answer