So I generated some nice looking lightmaps for my scene, all worked fine, except…
The build in lightmaps are all 1024x1024 and resulted in almost 300 Mb of data (on disk). This is unacceptable (for any game, let alone a mobile game like this).
But - No problem (I thought), I’ll just go through and set the ‘Max size’ for the lightmap textures themselves in the project view.
Lightmapper now reports instead of 300 Mb, now it’s down to 3.7 Mb. Great, that is workable (and the lightmaps are still reasonable quality).
Except…
When I build the game, it still packs the FULL SIZE textures into the APK, resulting in a ridiculously sized APK file.
I thought Unity pre-processes assets when you build for a specific platform so we don’t have to manually go through a resize textures etc? I thought that this was the WHOLE POINT of that ‘max texture size’ flag?
What am I doing wrong? How do I manage to get my lightmap textures down to a reasonable size without having to run batches outside of Unity? Or is that the only way to actually manage these assets?
Thanx in advance,
Mike W
ok this is a pretty big bug.
so i extracted the resulting APK that unity build and turns out that Unity refused to manage the lightmaps from this scene in particular because it wasn’t in a directory called ‘scenes’. They were dumped into the apk in raw form in the top-level of the APK assets folder, instead of being packed into the ‘res’ folder like the rest of the assets.
I moved the .unity file and the corresponding lightmaps into the ‘scenes’ folder of my project, rebuilt the APK and voila - apk drops 350 Meg in size because Unity properly processes the files.
Absolutely stupid. This scene is going to end up being an assetbundle (hence why it was outside of the normal folder structure), will experiment and confirm that assetbundles will properly package the files next.
Sigh, there’s 2 days I can’t get back.
I can’t comment on the “max texture size” issues you’re having, but I would like to recommend that you simply bake the lightmaps at a lower resolution in the first place. This way they’ll atlas down to a few lightmap textures instead of what sounds like dozens in your case. This allows for better static batching etc.
2-3 1024x1024 lightmaps is much more preferable than 32-48 256x256 lightmaps.
Don’t forget to use the “Resolution” visualisation checkbox when lightmapping with Beast. It’s a great way to optimize the atlas scalling.
One trick I use is that I run a script that automatically scales an object’s lightmap atlas size depending on the object size itself. Rationale behind being that you don’t need a huge definition on small detail objects vs big environmental objects. It also sets them static depending on tags and so on…
Unity is great for creating your own workflow. (oh and the atlas size is not exposed, you need to use SerializedObject property “m_ScaleInLightmap”)