Search Unity

New Material instance not updating?

Discussion in 'General Graphics' started by cardcastleusa, Oct 29, 2018.

  1. cardcastleusa

    cardcastleusa

    Joined:
    Mar 20, 2018
    Posts:
    9
    I have created a new material instance in order to have the roof and walls of my 3D builds fade in and out depending on if the player is within then. The problem is that when the material is applied to the mesh it does not update unless the material is clicked on within the editor.

    Video Example:



    The Material was created using the normal method via scripting
    Code (CSharp):
    1.  foreach (Material m in obj.GetComponent<Renderer>().materials)
    2.  
    3.         {
    4.  
    5.             m.SetFloat("_Mode", 2);
    6.  
    7.             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
    8.  
    9.             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
    10.  
    11.             m.SetInt("_ZWrite", 0);
    12.  
    13.             m.DisableKeyword("_ALPHATEST_ON");
    14.  
    15.             m.EnableKeyword("_ALPHABLEND_ON");
    16.  
    17.             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
    18.  
    19.             m.renderQueue = 3000;
    20.  
    21.         }

    Not 100% sure if i am missing a keyword or if something is just not working correctly with 2018.2.0f2
     
  2. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    Did you find the solution?