Override the mipmap level of a texture
Request that Unity overrides the mipmap level of a texture.
Read time 2 minutesLast updated a month ago
Override the mipmap level to influence which level Unity loads, rather than relying only on automatic mipmap streaming. You can do this in either of the following ways:
- The Priority property in the Texture Import Settings window of the texture.
- The Texture2D.requestedMipmapLevel API.
Use the Priority property
Follow these steps:
- Select the texture asset in the Project window.
- In the Texture Import Settings window, in the Advanced section, set a Priority value between -128 and 127.
When Unity needs to reduce mipmap levels to meet the memory limit, it considers textures in priority order from low to high until it meets the limit. This means textures with a higher priority value are more likely to keep their higher-resolution mipmap levels.
Unity removes a mipmap level of a lower-priority texture every time it considers textures at that priority or higher. For example, if you set one texture to a Priority of 1 and another texture to a Priority of 5, Unity might remove four mipmap levels before it considers the second texture.
You can also use the following APIs to set the Priority value:
- TextureImporter.streamingMipmapsPriority
- Texture2D.streamingMipmapsPriority
- IHVImageFormatImporter.streamingMipmapsPriority
Use the API
The Texture2D.requestedMipmapLevel API sets a specific mipmap level, overriding the level mipmap streaming would calculate. This is also necessary for objects Unity can't calculate a level for. Use the following APIs:
- Texture2D.requestedMipmapLevel to request that Unity overrides the mipmap level of the texture.
- Texture2D.IsRequestedMipmapLevelLoaded to check if Unity finished loading your requested mipmap level.
- Texture2D.ClearRequestedMipmapLevel if you no longer want to override the mipmap level.
For a basic example that pins a texture to a fixed mipmap level, refer to Texture2D.requestedMipmapLevel.
To manually calculate a level from the camera position, use the Mesh.GetUVDistributionMetric API to estimate the UV density of a mesh. For example code, refer to Mesh.GetUVDistributionMetric.
The level you request is still subject to your texture quality settings. The mipmap limit can cap the resolution, so a requested level of 0 might not load the texture's full resolution. Unity can also reduce the loaded level to stay within the memory budget, limited by the Max Level Reduction value and in order of texture streaming Priority.
Override mipmap levels on all textures
Use Texture.streamingTextureForceLoadAll to load all mipmap levels for all textures.