- Home /
How do I store textures as ".PNG" in the final build?
Hey all.
I'm an artist working on a board game for tablet devices. Due to the nature of these games, we have a large amount of unique of painted assets that do not compress well with standard formats. As such, we'd like to use .PNG compression to store our images in the final build, knowing that when they render they will be truecolour size in VRAM.
I've seen some scripts floating about, but no details to incorporate these into an artistic workflow; or how to set up the project so that these scripts become workable. As such, I'm a bit lost on how I can achieve this in our projects.
Any ideas would be greatly appreciated!
I'm not sure I totally understand the problem. Can't you just include the textures as PNG in your Assets/Resources folder and load them with Resources.Load in scripts, and then make sure you set their format to truecolor in the texture's import settings in the editor?
When you build your project, Unity packs the PNG file into the installer for the mobile platform, so it is stored as PNG in the final build. The truecolor format will be applied when you load the stored pngs into a Texture2D.
Hey CH,
Thanks for the quick response! Unfortunately, Unity doesn't allow you to keep textures under your resource folder as .PNG. It will automatically override this setting, and even if you manually assign formats .PNG is not a supported format.
In our experience, if you then build the final app, post-install it will have all textures included in the format you've specified in the editor. This means that they'll be Truecolour in our case, because that's the format we want to use when rendering the textures in our game.
We basically want to $$anonymous$$imize the size of the app after the user has installed it to their mobile device - we've done a quick calculation, and it saves us about 150 megabytes between truecolour textures and PNG textures.
Sorry if I come off as clueless btw - code is not my discipline, so I'm bound to miss basic things. As far as I know, Resources.Load deals with putting textures to objects - but we don't have any issues at the render stage. It's purely storage that's our concern!
Hey Chris,
That's simply not the case - Unity supports PNG and has for ages. Here's a screenshot from my own Resources folder right now:
You can find the list of supported image formats, including PNG, here: http://unity3d.com/unity/workflow/asset-workflow
It does not work with PNG internally at runtime, of course, since PNG is a compression format for storage on disc. When loaded into memory, the file is decoded into whatever format you choose in the import settings, e.g. Truecolor.
There's a difference between what files Unity can import and how they are stored in a build. Unity will store all assets in it's own asset-format. This doesn't use PNG compression on android. See the Android section on this page:
http://docs.unity3d.com/Documentation/Components/class-Texture2D.html
shaderop showed the only way to enforce PNG compression in an android build
Answer by shaderop · Jul 10, 2013 at 11:13 AM
If you change the extension of your PNG file to .bytes and then add them to your project, Unity will treat them as binary Text Assets and won't mess with their contents. Then it becomes possible to load them at runtime using Texture2D.LoadImage or similar methods.
Thanks for your help all!
I assume loading them at runtime means we can load all the .bytes files at the start of the game (on say, the loading screen) or does every single .bytes have to be loaded when the texture is actually needed?
Thanks for your help all!
I assume loading them at runtime means we can load all the .bytes files at the start of the game (on say, the loading screen) or does every single .bytes have to be loaded when the texture is actually needed?