- Home /
optimizing mesh & textures
hello there,
this is more of a general question. i'm in the process of optimizing my game and it seems that i need to reimport my meshes because i misunderstood some guidelines. so, before i start all the work of combining and wrapping my models i'd like to be sure that i'm doing it right this time ~_^
i have one center platform leading to four platforms with a small hut on each. since i read about combining i combined everything in close proximity to each other (i.e. on each platform) in packages of about 3000 verts and gave each of those packages its on texture/material. since i didn't plan it right from the start, i added a lot of small objects in each of the huts, again each with its own material. when i start the game on a computer without proper gpu i end up with 5 fps, which is really quite frustrating.
now i read in the documentation that it's not advised to combine the meshes in a 3d application (which i unfortunately did). does that mean that i should really combine nothing at all? i have lots of wooden boards, railways, ropes, small stuff, do i just leave it as single meshes and import everything into unity?
and how would i go about combining all of it in unity? i plan on wrapping the texture of all static objects into one texture atlas, but since 4k is the limit on textures i'm not sure if that is enough. should i put the texture of dynamic/moving objects into the texture atlas as well? does it even make a difference if they're dynamic? and: do i use as much texture atlases as i can or is there a case when it might be better to use a single material?
i would be grateful if any of you could share how you do it - how do you plan your meshes and textures, what is your workflow? thanks!
Answer by syclamoth · Sep 14, 2011 at 11:01 AM
I had a similar problem recently, where I built all of my buildings out of modular segments in maya which could be assembled when they were brought into Unity. The problem was, that when I ran it the game went down to about 15 fps, and was virtually unplayable (although, I admit, not as bad as yours). My solution was twofold- I first attached a script to all the buildings which (when the level was loaded) iteratively searched through every single mesh renderer in every building and combined every mesh that used a shared material using Mesh.CombineMeshes to create a much smaller number of objects (thus reducing draw calls). Because I did this once for each building, every building got combined into a set of 8 or so huge meshes which interlocked (one for walls, one for cornices, one for windows etc).
The second part of the solution was to put a script on each one of these joined meshes which automatically set the shader to the default VertexLit if the object was a certain distance away from the camera (which was polled randomly every 0.5-1.5 seconds so as not to have a huge performance hit), making rendering significantly less expensive for less relevant meshes.
When it was all set and done, I got performance increases of between 100 and 150%- not great when you consider what I was improving from, but still better than what I was getting before.
An interesting thing to note is that I later purchase Unity Pro- and it immediately made my scene populate 4 gig of memory and then crash whenever I ran it! I discovered that this was because of unity's static batching conflicting with my combiner script- meaning that the objects were being combined automatically during export, and then copied about 100 times and combined AGAIN by mine! I turned off my custom script, and discovered (to my horror) that the Unity static batching actually didn't do as good a job (because it had to be more generalised).
In the end, I had to scrap that level, but I learned some important lessons- mainly to keep your environmental meshes as simple as possible, and to try to reuse textures as much as you can. There are a lot of creative ways you can make the same texture look different- by using different parts of it in different ways, or by rotating and scaling it. In the end, for small static objects, I would say that a texture atlas would have to be the way to go, assuming that you then combine all the objects into a single mesh at runtime.
thank you very much for your detailed answer! i'm very grateful for the experience of other people - there are a lot of tutorials, but i didn't find any that focus on the general workflow.
i tried to optimize the performance with lightmapping, but strangely it made the fps even worse. maybe i just didn't do it right ;)
i'll rework the models now so that the buildings share one texture and all the small objects share another one and then let unity do the batching - i'm using the Pro Version of Unity, so i hope it works.
thanks again, i'll be sure to post if i come to any interesting conclusions!
Your answer
![](https://koobas.hobune.stream/wayback/20220612212730im_/https://answers.unity.com/themes/thub/images/avi.jpg)