Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

getting material break outline material

Discussion in 'General Graphics' started by Deleted User, Jun 26, 2022.

  1. Deleted User

    Deleted User

    Guest

    Im trying to make a top down game where the item disappear if not in line of sight and if you are close enough it will put a outline on the item, im using the quick outline of the store and using the alpha of a color of the material to disappear the object, it need to be this way to make a fade in and out effect but the getComponentsInChildren<Renderer> break the outline material making it always have a white outiline, here is the part that is breaking
    Code (CSharp):
    1. private void setAlpha(float alpha) {
    2.         Renderer[] children = mesh.GetComponentsInChildren<Renderer>();
    3.         Color newColor;
    4.         foreach(Renderer renderer in children) {
    5.             foreach (Material material in renderer.materials) {
    6.                 if (material.name.Contains("Outline"))
    7.                     continue;
    8.                 newColor = material.color;
    9.                 newColor.a = alpha;
    10.                 material.color = newColor;
    11.             }
    12.         }
    13.     }
    i already commented everything beside the

    Renderer[] children = mesh.GetComponentsInChildren<Renderer>();
    and that line is what is breaking the outline material

    EDIT1:
    i commented the inner foreach and stopped breaking, now im lost on what could be, when i tried i commented just the commands inside the foreach loop and was still breaking

    EDIT2:
    found the problem, the renderer.materials command create a copy of the materials, so i had to change the outline base script to always search for the new material that is created
     
    Last edited by a moderator: Jun 26, 2022