Version: 2021.1
Streaming Controller
Physics

Mip Map Streaming API

This page contains the following sections:

Overview

Use the API to apply more control over how Unity streams Textures. You can override which mip map level to load for specific Textures, while the Mip Map Streaming system automatically manages all other Textures. You might have specific gameplay scenarios where you know that Unity needs to fully load certain Textures. For example, moving large distances quickly, or using instantaneous CameraA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary
cuts, can cause noticeable Texture quality changes while the Mip Map Streaming system streams the mip maps from the disk into memory. To reduce this problem, you can use the API to preload mip maps at a new Camera location .

To enable and control Mip Map Streaming on a Texture, use the following properties:

Mip Map Streaming automatically reduces the size of Textures until they fit into the Mip Map Streaming Memory Budget. The Texture’s Mip Map Priority number is roughly a mip map offset for the Memory Budget. For example, with a priority of 2, the Mip Map Streaming system tries to use a mip map that is two mip levels higher than other Textures with a priority of 0. Negative values are also valid. If it can’t do this, it uses a lower mip level to fit the Memory Budget.

Controlling the Mip Map Streaming system

These properties are read-only at runtime:

To control what happens at runtime, use the following static properties:

Configuring the Memory Budget

The Memory Budget property determines the maximum amount of memory Unity uses for the textures in your sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
. It is set to 512MB by default. The Memory Budget has a high impact on your scene when using texture streaming. If your memory budget is too small, Unity lowers the resolution of textures in your scene. This can cause textures to pop or load slowly. However, the memory budget should be as small as possible to allow memory for other resources.

To figure out what your memory budget should be:

  1. Look at the Texture.desiredTextureMemory value when your project is running.
  2. Set the Memory Budget value slightly higher than the Texture.desiredTextureMemory value.

This makes sure there is enough texture memory available for the most resource-intensive areas of your scene and prevents textures from dropping to a lower resolution. If you have extra memory available, you can set a larger memory budget so that Unity can keep texture data that is not visible in your scene in the streaming cache.

Controlling Cameras for Mip Map Streaming

In the Quality Settings (Edit > Project SettingsA broad collection of settings which allow you to configure how Physics, Audio, Networking, Graphics, Input and many other areas of your project behave. More info
See in Glossary
> Quality), use Add All Cameras to specify whether Unity should calculate Mip Map Streaming for all Cameras in the Project. This is enabled by default.

For fine-grain control over which Cameras are active, use the Streaming Controller component on the same GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
as the Camera component. This takes the location and Camera settings (such as Field of View) directly from the Camera component.

If the Camera is disabled, Unity does not calculate Mip Map Streaming for it, unless the Streaming Controller is enabled and in the preloading state. When the Streaming Controller and associated Camera are enabled, or if the Streaming Controller is in a preloading state, then Unity calculates Mip Map Streaming for this Camera. If the Streaming Controller is disabled, then Unity does not calculate Mip Map Streaming for this Camera.

The Streaming Controller component
The Streaming Controller component

The Streaming Controller component contains the Mip Map Bias setting. To control this via API, use StreamingController.streamingMipmapBias.

Use this setting to force Unity to load smaller or larger mip map levels than the Mip Map Streaming system has chosen for those Textures. Use the numerical field to set the offset that Unity applies to the mip map level. Unity adds this offset to all Textures visible from this Camera.

Camera cuts

When cutting from one location to another, the Mip Map Streaming system needs time to stream the required Textures into Unity. To trigger preloading at a disabled target Camera location, call StreamingController.SetPreloading on the target Camera’s Streaming Controller component. You can specify a time-out to end the preloading phase. To automatically enable the Camera at the end of the preloading phase, set the activateCameraOnTimeout flag to true in script. To disable a Camera after you cut from it to the new one, pass that Camera as the disableCameraCuttingFrom parameter.

void StreamingController.SetPreloading(float timeoutSeconds=0.0f, bool activateCameraOnTimeout=false, Camera disableCameraCuttingFrom=null)

To cancel or query the preloading state, use the following methods:

To determine whether the Mip Map Streaming system is still loading Textures, you can query the following properties:

Note that there is delay between when you enable a Camera and when these properties become a value other than zero. This delay is because the Mip Map Streaming system calculates the mip maps using time-sliced processing. For this reason, during a Camera cut you should wait a minimum length of time before the cut. Texture budget and Scene movement can cause continuous Mip Map Streaming, so you also need to set a maximum length of time before the cut.

Load a specific mip map

To override the mip level calculation for a specific Texture, use Texture2D.requestedMipmapLevel. This is an exact mip level ranging from 0 to the maximum mip level of the specific Texture, or the Max Level Reduction value if that is lower. 0 is the highest resolution mip.

To check if your requested mip level has loaded, use Texture2D.IsRequestedMipmapLevelLoaded.

If you no longer want to override the mip level you requested and instead want the system to continue to calculate mip map levels, use Texture2D.ClearRequestedMipmapLevel to reset the value.

To get an estimate of the UV density on a MeshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary
, use the following:

float Mesh.GetUVDistributionMetric(int uvSetIndex)

You can use the UV distribution metric to calculate the mipmap level you need, based on the position of the Camera. See Mesh.GetUVDistributionMetric for example code.

To override the system and force all mips to load, use Texture.streamingTextureForceLoadAll.

Related API methods

To get and set a Texture assigned to a Material, use:

To get all Texture properties on a Material, use:

Debug or profiling API

To get per-texture streaming info in material properties that can be used for creating debug visualisations use Texture.SetStreamingTextureMaterialDebugProperties.

You can use Texture.SetStreamingTextureMaterialDebugProperties] to assign streaming status information for each texture to material properties. You can then use these properties in the shader to create debug visualizations.

You can also use these properties to create Mipmap Streaming profiling and debugging tools for your project.

To get information about the number of Textures or renderers the Mip Map Streaming system is interacting with, use the following properties:

To get information about mipmap levels for a texture, use the following properties:

Lightmaps

You can use the Mip Map Streaming system to stream lightmaps. You can edit the Texture settings directly, but they reset to their default values when Unity regenerates the lightmaps. The Player SettingsSettings that let you set various player-specific options for the final game built by Unity. More info
See in Glossary
(Edit > Project Settings > Player) provide two controls to set streaming and priority for generated lightmaps: Lightmap Streaming Enabled and Streaming Priority.

Edit > Project Settings > Player > Other Settings
Edit > Project Settings > Player > Other Settings

Play Mode

Mip Map Streaming is enabled in Play Mode by default. However, when running in Play Mode, the Editor overheads bias the statistics. To get accurate figures, test the application on the target device.

When Mip Map Streaming is enabled in Play mode, but not enabled in Edit mode (or the other way around), toggling in and out of Play mode takes slightly longer. To disable Mip Map Streaming in Play mode, go to the Editor Settings (Edit > Project Settings > Editor), navigate to Streaming Settings and disable Enabled Texture Streaming in Play Mode. This prevents Unity from unloading and reloading mip map data, and should speed up the Play mode workflow.

Edit > Project Settings > Editor > Streaming Settings
Edit > Project Settings > Editor > Streaming Settings
Streaming Controller
Physics