Search Unity

Official Material Variants now available in Unity 2022.1

Discussion in 'General Graphics' started by Matjio, Jun 10, 2022.

  1. Matjio

    Matjio

    Unity Technologies

    Joined:
    Dec 1, 2014
    Posts:
    108


    Welcome to the Material Variants discussion thread. You can use this thread to ask for help, share feedback, and have discussions about this new feature available in Unity 2022.1.

    We are super excited to introduce this new system (which has been requested for a long time and quite highly voted on our public roadmap!) to manage variants of materials at scale!

    It allows for reuse and improve management of materials that share most surface properties and differ only through others (think "Prefabs for Materials").

    You can read more about it in our documentation and blog post.

    Once you have tinkered with the system, please take 5 minutes to fill our poll that will help us validate the quality of our initial design.

    Best,
    The Unity Graphics Team
     
    Last edited: Aug 5, 2022
  2. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Really nice new feature!

    I'm going to make full use of it, thanks!

    ( About the survey, sorry not doing those, as there is too much data mining questions that have nothing todo with the material variants, like the first questions about organisation etc. I may be wrong but I feel like if I don't put there an organisation with millions of revenue my answers will not be valued the same )
     
  3. Sisay

    Sisay

    Joined:
    Dec 6, 2012
    Posts:
    57
    Material variant increases the number of draw calls.
    Property block has more efficiency?
     
  4. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    Material variants are for workflow, not optimization.
    Every variant is like separate material.
     
  5. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    The system of material variants exists only in the editor for better workflow/QoL.
    I believe in the background, for a built game, each "variant" is a new material.

    It's mentioned in the blog if you want more information.
     
  6. Sisay

    Sisay

    Joined:
    Dec 6, 2012
    Posts:
    57
    a bit strange, so the script with c # and property block changing values gives me 1 material on many objects and the system written by unity gives only utility in the editor :(
     
  7. michalpiatek

    michalpiatek

    Joined:
    Feb 26, 2021
    Posts:
    81
    Is there any way I can batch-convert a series of existing materials to be children of another material that uses the same shader? I'd really like to use material variants on the project I'm working on right now but I have 200+ materials that I'd like to all be child materials of one master material. Would take quite some time to convert by hand :rolleyes: Maybe there's something I can add to the YAML to do this?
     
  8. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    If serialization of material variants is as "brilliant" as serialization of prefab variants than I would not stick my fingers into it.
     
  9. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    253
    Material variants are great. Can we have ScriptableObject variants?
     
    michalpiatek likes this.
  10. michalpiatek

    michalpiatek

    Joined:
    Feb 26, 2021
    Posts:
    81
    +1 for this. It would be incredibly useful.

    Also +1 for replying my previous question about converting materials to variants, please?
     
  11. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,278
    This is fantastic! Anything that reduces data copying is a huge + for me. Scriptable Objects being next would definitely be great ;)
     
  12. ddreams_anne

    ddreams_anne

    Joined:
    Dec 13, 2020
    Posts:
    18
    @Matjio I started updating the Measured Materials Library (We have you covered with the Measured Materials Library | Unity Blog) a month ago for Unity 2019, 2020, 2021, 2022 and 2023. Since I am still working on the 2019 URP version I am glad I found this forum before I started on the other versions, which I will probably cancel now, as the variants solution is way better. Looking at the image you used at the start of the thread I am wondering if you are also updating (extending) the Measured Materials Library using material variants (which should make it a lot easier as you can just create the master materials and base variant of those)?

    If not, do you mind if I would update it to a variants version and is there a way I can get the model that you are using in the example at the start of this thread? I am currently using the older Unity ball model for previews.
     
  13. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,087
    This feature seems to have broken the copying of Material properties from and to TextMeshPro materials and broken the Create Preset Material feature of TextMeshPro, too.
     
  14. Matjio

    Matjio

    Unity Technologies

    Joined:
    Dec 1, 2014
    Posts:
    108
    @AnteNomspa Sorry for the delay! I don't know of any work planned on upgrading the measured materials to the variant system, which indeed would make sense.
    The material ball is available on HDRP sample scene from the Hub.
     
  15. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Hey, can you explain how we can manage shader keywords with material variants?

    I would like all children of a parent material to inherit the keywords of the parent.
    Using
    ValidateMaterial
    works when the child is first loaded. However, after that point, changing keywords on the parent doesn't change the children.
    ValidateMaterial
    is not called.

    Here's a simple script I'm using for my materials:
    Code (CSharp):
    1. public class MyShaderGUI : ShaderGUI {
    2.  
    3.     public override void ValidateMaterial(Material material) {
    4.  
    5.         if (material.parent != null) {
    6.  
    7.             material.shaderKeywords = material.parent.shaderKeywords;
    8.         }
    9.     }
    10. }
    Is there some API to access the children of a material?
    So that when
    ValidateMaterial
    is called on the parent, I can iterate over the children and apply the keywords there?