Search Unity

Setting _Metallic property on Material failing

Discussion in 'Scripting' started by miniduck, Dec 15, 2017.

  1. miniduck

    miniduck

    Joined:
    Sep 27, 2012
    Posts:
    117
    Hello

    Trying to set metallic property on material but is constantly failing.
    When using Standard Roughness, should this be set with _Metallic property?

    Running 2017.2.0f3

    Error:
    Simple editor script to replicate:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. public class TestMetallic : MonoBehaviour
    4. {
    5.     [MenuItem("Assets/Test Metallic...")]
    6.     public static void test()
    7.     {
    8.         Material material = new Material(Shader.Find("Standard (Roughness setup)"));
    9.         Texture2D t = new Texture2D(256, 256);
    10.         material.SetTexture("_Metallic", t);    
    11.     }
    12. }
     
  2. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
  3. miniduck

    miniduck

    Joined:
    Sep 27, 2012
    Posts:
    117
    Many thanks!

    material.SetTexture("_MetallicGlossMap", t);