Material Variants

Is it possible create materials variants programmatically in unity editor script?
Also to find a parent material of a variant?

Oh, found it. just set .parent property of material to make a variant.