Search Unity

How do I change the alpha levels of materials I added in blender?

Discussion in 'Editor & General Support' started by guzzo9000, Apr 19, 2019.

  1. guzzo9000

    guzzo9000

    Joined:
    Apr 17, 2019
    Posts:
    3
    When creating my models for the game I am making, I simply created different colored materials and assigned them to different spots of the mesh and that seemed to be a pretty easy way to make low poly assets.

    For what I am doing, I need to be able to edit the alpha level of all of the materials at the same time.

    For objects that I simply assigned a material, I could edit the material and make its rendering mode to cutout. Then, in the code, all I do is:
    Code (CSharp):
    1. Color color = this.GetComponent<MeshRenderer>().material.color;
    2.  
    3. color.a = 0.5f; //or any value between 0 and 1
    4.  
    5. this.GetComponent<MeshRenderer>().material.color = color;
    6.  
    The problem with my custom made models is that I can't seem to edit the rendering mode, or anything else, on the materials so it is staying at Opaque which doesn't support changing alpha levels. I can't seem to figure out how to change them in blender or in Unity. Also, I don't know if the fact that there are multiple materials per model is causing a problem.

    Does anybody know any solutions?

    Edit:

    I figured out that I can enable or disable the MeshRenderer of the objects instead of editing the alpha levels:
    Code (CSharp):
    1. MeshRenderer mesh= this.GetComponent<MeshRenderer>();
    2.  
    3. mes.enabled = false; //for making it invisible
    4. mes.enabled = true; //for making it visible
    5.  
    6.  
    this allows me to make my custom models invisible despite the fact that the materials are weird.

    I lost the ability to fade in and out, but being as this is a high school project, I don't really need such a nice feature. :p
     
    Last edited: Apr 20, 2019
  2. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,815
    I don't know about Blender.

    But for Unity you can change the shader mode at runtime when using the Standard Shader:
    material.SetInt("_Mode", 2); //Set it to fade mode
    material.SetInt("_Mode", 1); //Set it to cutout mode
    material.SetInt("_Mode", 0); //Set it to opaque mode

    Then the the object will fade out according to the alpha value of the main color (for fade or transparent mode).
    For cutout, you can specify the cutoff threshold:
    material.SetFloat("_Cutoff", ...); //Set it to opaque mode

    https://docs.unity3d.com/ScriptReference/Material.SetInt.html
     
  3. guzzo9000

    guzzo9000

    Joined:
    Apr 17, 2019
    Posts:
    3

    Unfortunately this didn't work for me, but I appreciate your intent to help. I've figured out another way that doesn't involve manipulating the alpha level so I will just go with that.