Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ShaderVariantCollection

ShaderVariantCollection records which shader variants are actually used in each shader.
Read time 5 minutesLast updated 4 days ago

Definition

  • Type: Class
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
  • Inherits from: Object
public sealed class ShaderVariantCollection : Object

Remarks

This is used for shader preloading ("warmup"), so that a game can make sure "actually required" shader variants are loaded at startup (or level load time), to avoid shader compilation related hiccups later on in the game.
In Unity, many shaders internally have multiple "variants", to account for different light modes, lightmaps, shadows and so on. These variants are identified by a shader pass type, and a set of shader keywords. See ShaderVariantCollection.ShaderVariant.
Typical use of ShaderVariantCollection is to record the shader variants used during a play session from the editor (under Graphics Settings), save them out as an asset, and add to the list of preloaded shaders (again in Graphics Settings). Additionally, you could call ShaderVariantCollection.WarmUp on a ShaderVariantCollection object manually.
ShaderVariantCollection generally replaces the old Shader.WarmupAllShaders function.

Constructors

Constructor

Description

ShaderVariantCollection()Create a new empty shader variant collection.

Properties

Property

Description

isWarmedUpIs this ShaderVariantCollection already warmed up? (Read Only)
shaderCountNumber of shaders in this collection (Read Only).
variantCountNumber of total variants in this collection (Read Only).
warmedUpVariantCountNumber of total variants in this collection that are already warmed up (Read Only).

Methods

Method

Description

AddAdds a new shader variant to the collection.
ClearRemove all shader variants from the collection.
ContainsChecks if a shader variant is in the collection.
RemoveRemoves shader variant from the collection.
WarmUpPrewarms all shader variants in this shader variant collection.
WarmUpProgressivelyPrewarms the given number of shader variants in this shader variant collection.

Structs

Struct

Description

ShaderVariantCollection.ShaderVariantIdentifies a specific variant of a shader.

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.