Assigning a Pre-Defined Material

If you want to assign Pre-Defined Materials via code, you must be sure that the Materials asset exist in your project. To Ensure this, please navigate in unity to Tools -> Better UI -> Settings -> Select Material Definitions.

To apply it, assign the ID of the material to the MaterialType property of your BetterImage or BetterRawImage. See Pre-Defined Materials to lookup the IDs.

Everything else is handled internally by Better UI.


The following code sets the Material of "myImage" to "Hue Saturation Brightness":

myImage.MaterialType = "Hue Saturation Brightness";

It is also possible to set the Material Effect via code by setting the MaterialEffect property.


The following code sets the Material Effect of "myImage" to Additive:

myImage.MaterialEffect = MaterialEffect.Additive;

Changing Material Properties

As the variables of the pre-defined materials are stored in the vertex information for better performance on massive usage, they cannot be accessed by name.

Instead, you can access them via their material property index. This index is zero-based and in the order of how the properties appear in the inspector. See Pre-Defined Materials for reference.

To change the value via code, the SetMaterialProperty() Method needs to be called on the respective BetterImage or BetterRawImage.


The following code shows how to set the Brightness variable for an Image "myImage" which has a Hue-Saturation-Brightness material applied.

Note that HUE and SATURATION are not used here but are displayed for reference. Instead of BRIGHTNESS you could also simply insert 2.

const int HUE = 0;

const int SATURATION = 1;

const int BRIGHTNESS = 2;


myImage.SetMaterialProperty(BRIGHTNESS, 0.5f);