My game reads my levels from a text file and instantiates the tiles, hopper, and enemies. For example the following level ( screenshot ) is created from the text file like this:
oooo
oooo
HC
ooCoo
oo*oo
The basic premise of my game is that each time the Space Hopper bounces on a tile it changes colour. When all tiles
are the same colour the level is complete.
When it came time to start optimizing it became clear that each instantiated tile takes up a draw call. Combining the tiles using CombineChildren reduces the draw calls but obviously all the tiles then become the one colour ( material ), which I understand is a condition of CombineChildren.
I was hoping that by offsetting the UVs of each individual tile as it is bounced on to correspond with different areas of a texture atlas I could get round the problem.
I suppose the question is :
Is it possible to alter the UV co-ords of an individual object AFTER it has been combined using CombineChildren ?
I can’t answer your actual question, because I never use that and have no plans to start. However, it doesn’t matter, because it’s a bad approach, at least for your situation. What you should do, instead, is just use a vertex-colored shader. You can just put “light” into the vertex colors, further optimizing. All of the platforms will dynamically batch, so only worry about actually putting them into the same mesh if it’s necessary.
Thanks Jessy, I will have a look at that when I get home.
Are there any further tips you could give me on how to get started, because although I think I understand the principal I cant quite see where to start.
I don’t know what knowledge you have, but it sounds like you don’t have experience with vertex colors. No problem; I didn’t know about or understand them until last year either. What I’ll suggest, for now, is that you try them out, keeping your lighting at first. I can’t tell what you’re doing with lighting - the front faces of the platforms are bright in the back but dark in the front. Are you using a point light?
Anyway, add “Bind “normal”, normal” to that shader I linked to, so lighting works. (Sorry I can’t format code right now but I’m on my iPhone.). Read up about the Mesh class, on its script reference page, and specifically you’ll need to work with Mesh.colors. Just assign the same color for the entire array, when you want a change, instead of using Material.color like is typically done when an object-level tint is desired.
An alternative to this is to use different stored materials, and change materials, instead of these other methods. You’ve only got four colors there, and everything is low-poly, so all these methods should be about as fast as any other. You definitely should have vertex color manipulation in your bag of tricks, though, and you definitely need to learn to share materials, so your draw calls stay low, and you should know when not to rely on texture mapping. Any time you need large areas of solid color, especially with crisp edges, texture mapping probably isn’t the right solution.
Just continue to post here with anything you need clarified, and please let us see what kind of solutions you try out.
Thank you so much - Draw Calls down from 30+ to 10+
I ended up using Mesh.colors as you described above to assign different colors to the seperate tiles, using the Mobile/Vertex Colored shader included with Unity 3.
I owe you a drink - never would have thought to do it that way without your wise words…
I checked that shader you just mentioned to make sure it was a good choice. As it turns out, it’s broken. I believe they meant to write “Lighting On”, but actually used “off”. So if your game looks good with that, I suggest using the one I linked above, because it’s faster and simpler. Otherwise, I’ll help you modify something to utilize light. I’ll report a bug about the shader you’re using later.