Unity3d game development How to reduce the size of the installation package

Source: Internet
Author: User

The first thing to do is to see which files are the most space-occupying, then they are the preferred optimization objects.


You can find this information in "Editor Log" after you have just completed a build.


How to open editor Log:



That's what it looks like on a Mac:

As you can see, this log provides a summary of resources: The total size of all types of resources, and the percentage. The size of a single file is also reduced. Please click "Dog planing Learning net" for more highlights.

Incidentally, "File headers" in the resource type are not the resources themselves but are added to the original resources to store additional data for reference and configuration information. You can usually ignore the size of the data, but if you have a very large resource file in your "Resources" folder, this data can be very large.

This log can help you identify which files you might want to erase or optimize.

But before you start, you need to know a few things:


1, Unity re-coding will make the resource into its own internal format, so the type of resource source file is irrelevant. For example, if you have a multi-layer PS texture, it will be spliced and compressed before the build. So deliberately turning this texture into PNG format does not help to reduce the size of the packet. It is better to use the most convenient format when developing.

2. Unity will remove those resources that are not used in your project when build, so we do not need to manually find out to delete. But scripts are not erased (though they do not account for resources), and all resources in the "Resources" folder are not automatically deleted (because unity cannot tell which ones are needed). So we want to make sure that the "Resources" folder is all we really need to use. Of course, you can also reduce the size of the package by dynamically loading assetbundles instead of resources in the "Resources" folder. Please click "Dog planing Learning net" for more highlights.


Some suggestions:



Textures (textures)

Textures usually occupy most of the space. The first step is to choose a compressed texture format (DXT or PVRTC). If this does not reduce the amount of space it occupies, then try narrowing the size of the texture. You don't need to modify the resource itself, just select the texture under Project and then set the max size under INSPECTPR.



A good way to do this is to find an object in the scene that uses the texture, enlarge the screen, and then lower the Max Size while looking at the object in the scene until it looks bad, and you know what's best for you.
















By comparing the above graphs, we can see that selecting the max size of 512 or even 256 can be effective, and the resource size can be significantly reduced. Modifying a texture's max size does not affect the resource itself, it only changes its resolution in the game. The following table lists the size of space occupied by different picture formats (per BPP: bytes/pixel)


The size of a picture formula: Width * Height * bpp, if you are using a mipmap map, then its size will be about 3 times times the normal picture.

Unity is compressed by default when importing textures, and in order to save time during development, we can turn this feature off manually in preferences


At build, unity will compress the texture regardless of whether you check it or not.


Grids and animations (Meshes and animations)

Both the mesh and the imported animation (Animation Clips) can be compressed. After you have selected a model, you can set it in Inspector.



However, they are compressed, which can cause errors. So it's best to first figure out what degree of compression is acceptable within the range. In addition, mesh compression only reduces the size of the data file, and does not reduce the memory consumption at run time. Reducing animation keyframes will reduce both, and in general we should turn it on.




Dynamic link library (DLLs)

By default, unity will only include the following DLLs at build:



We should avoid references to System.dll or System.Xml.dll, otherwise they will be included in the build, and they will occupy a few m of space.

If you do need to parse the Xml in the game, you can use "Mono.Xml.zip" instead of a system-level DLL. In addition, most generic containers are already included in the standard library, and only a few are in the System.dll, so you should avoid using them if possible.


Reduce the size of the. NET libraries used on your phone

Unity provides two sets of. NET Api:.net 2.0 and. NET 2.0 subset for mobile devices


. NET 2.0 provides an almost complete set of API features, but many times the game doesn't use that much, resulting in a lot of extra code taking up valuable space resources. To avoid wasting, we can use the. NET 2.0 subset (equivalent to a subset of. NET 2.0) provided by unity. In order to save resources, many of the generally used examples of libraries are removed, so this optimization is also useful, just to make sure that our code works properly.
Can be set in "Player Settings"

Unity3d game development How to reduce the size of the installation package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.