Search Unity

Bug Material Variants not working as intended with custom Shaders

Discussion in 'Editor & General Support' started by Necka_, Jul 21, 2022.

  1. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    Hello,

    I was extremely excited to have Material variants, the idea was to be able to create parent materials with master settings and children materials with their specific stuff (like albedo/normal textures)

    I'm using a toon shader here, my parent is where I planned to set the stylization settings for all the children while those children have override for albedo/normal/emissive textures.

    Unfortunately that doesn't work. I mean the textures are there no problem, but changing the properties do not have any effect on the children (the property sliders/numbers are updated in the children correctly, but the material doesn't change visually)

    Worst, changing the property on a child doesn't change anything either.

    Here's an example.
    That's the parent material where as I said, all the stylize properties are configured
    upload_2022-7-21_17-44-7.png

    Now here is a material variant where only the top stuff is overridden:
    upload_2022-7-21_17-45-0.png

    The simplest example is Dissolve, where if the material is not a variant, I can use the slider and the mesh will dissolve, but if it's a variant, the slider doesn't do anything.
    If I do it on the parent or on the child as an override, it has no effect.
    If I switch the material variant to a regular material, then it still doesn't work until I turn off dissolve option and turn it on again.

    So it's like some kind of a bug, and it's the same for all custom properties in the list.

    I've read that Material variants were supporting Custom shaders, but it seem to not be reliable at all.

    Am I missing a point here?

    My goal was to be able to tweak common settings from a central point (the parent materials) instead of having to do it on every materials scattered around the project folders.

    I'm using Unity 2022.1.10 in URP 13.1.8
     
  2. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    Troubleshooting a little more, I found out at least part of the issue.

    Going from scratch, I created a new Material and applied the custom shader.
    Here is the Debug view for this new material (note the Keywords):
    upload_2022-7-21_18-49-13.png

    Then right click on this material => create Material variant.
    Here is the debug view of this new variant:
    upload_2022-7-21_18-49-43.png

    So I guess that's where the issue is. The Keywords are not propagated to the variants, maybe there is more to it but that's above my paygrade