Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Material/Shader inspector doesn't update emissions values

Discussion in 'Editor & General Support' started by MvNimwegen, Dec 19, 2019.

  1. MvNimwegen

    MvNimwegen

    Joined:
    Dec 19, 2019
    Posts:
    57
    Hi guys,

    I'm trying to a simple script where I manipulate emission of a material. I want to enable and disable emission and also change the emission color.
    Here the issue: The script works perfectly fine, but the inspector doesn't update the new values. If I disable emission from script, the inspector still shows that it is enabled, even though the material doesn't actually emit anymore. If I select another game object, then open the material inspector again, the old, not updated, emission values are applied again and the material starts to emit again!
    If I keep the material inspector closed/collapsed, this issue doesn't occur.

    The code I use to control emission is as follows:
    Code (CSharp):
    1.  
    2. currentMaterial.EnableKeyword("_EMISSION");
    3. currentMaterial.SetColor("_EmissionColor", LightColor);
    4.  
    5. currentMaterial.DisableKeyword("_EMISSION");
    6.  


    Is this the right way to do this? Am I missing something? Am I the only one with this problem?

    Thanks!
     
  2. MvNimwegen

    MvNimwegen

    Joined:
    Dec 19, 2019
    Posts:
    57
  3. alexutzblue

    alexutzblue

    Joined:
    Nov 8, 2016
    Posts:
    2
    same behaviour here
     
  4. trxr

    trxr

    Joined:
    Sep 18, 2018
    Posts:
    1
    Code (CSharp):
    1. private void Start()
    2.     {
    3.  
    4.         currentMaterial = GetComponent<Renderer>().material;
    5.         Instantiate(currentMaterial);
    6.     }
    solved this issue for me
     
  5. GYUN

    GYUN

    Joined:
    May 23, 2017
    Posts:
    1
    Same problem :(
    solved.
     
    Last edited: May 13, 2021