Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Shader.PropertyToID

static function PropertyToID(name: string): int;
static int PropertyToID(string name);
static def PropertyToID(name as string) as int

Description

Gets unique identifier for a shader property name.

Using property identifiers is more efficient than passing strings to all material property functions. For example if you are calling Material.SetColor a lot, or using MaterialPropertyBlock, then it is better to get the identifiers of the properties you need just once.

Each name of shader property (for example, _MainTex or _Color) is assigned an unique integer number in Unity, that stays the same for the whole game. The numbers will not be the same between different runs of the game or between machines, so do not store them or send them over network.

See Also: Material, MaterialPropertyBlock.