Skip to content

πŸš€ Getting Started

Dennis edited this page Feb 2, 2025 · 6 revisions

πŸš€ Getting Started

1️⃣ Add the CustomUI Component

  1. Select a UI component in Unity (e.g., Image, TextMeshProUGUI)
  2. Open the Inspector panel
  3. Click Add Component and search for UIMaterialModifier

2️⃣ Assign a Shader

  1. Ensure the UI component's Material uses a shader that supports modification.
  2. Example: UI/Unlit/Transparent

3️⃣ Modify Shader Parameters

You can modify properties directly in the Inspector:

  • Color (_Color)
  • Transparency (_Alpha)
  • Saturation (_Saturation)
  • Contrast (_Contrast)

Or modify them via script:

using Dennis.UI;

CustomUI customUI = myGameObject.GetComponent<CustomUI>();
customUI.SetFloat("_Saturation", 1.5f);
customUI.SetColor("_Color", Color.red);

⚠️ Shader Property Not Found Warning

πŸ”Ή Why Does This Happen?

If you enter a property name that does not exist in the shader, you will see a yellow warning in the Inspector: Shader does not have property 'aaa' image

πŸ”Ή How to Fix This Issue

1️⃣ Check the Shader Property Name

  • Open the Material Inspector and find the exact property name.
  • Ensure it starts with _ (e.g., _Color, _Saturation).

2️⃣ Verify That the Shader Supports the Property

  • Open the Shader Code (.shader file) and check if the property exists.
  • Example:
    _Saturation ("Saturation", Range(0, 2)) = 1
  • If the shader does not define _Saturation, adding it in UIMaterialModifier will have no effect.

3️⃣ Use the Correct Property Type

Property Name Expected Type Incorrect Type
_Color Color Float, Int
_Saturation Float Color, Vector4

⚠️ Shader Property Type Mismatch Warning

πŸ”Ή Why Does This Happen?

If you select a shader property type that does not match the actual property type, you will see a yellow warning in the Inspector:

Shader property '_Color' is expected to be Color, but you assigned Float.

image

πŸ”Ή How to Fix This Issue

1️⃣ Check the Shader Property Type

  • Click on the Material attached to your UI element.
  • Find the shader property you want to modify.
  • Verify its type in the shader code (e.g., _Color should be Color, _Saturation should be Float).

2️⃣ Select the Correct Type in the Inspector

  • If _Color is a Color, select Color from the dropdown.
  • If _Saturation is a Float, select Float from the dropdown.

3️⃣ Fix it in the Inspector

  • βœ… Before (Wrong)
    • Property Name: "_Color" Type: Float 🚨 Warning: Shader property '_Color' is expected to be Color, but you assigned Float.
  • βœ… After (Fixed)
    • Property Name: "_Color" Type: Color βœ… No Warning

πŸ”Ή Best Practices

  • βœ… Always check the shader property type before modifying it.
  • βœ… Use Inspector > Material to confirm available properties.
  • βœ… Only modify properties that exist in the shader.
  • βœ… Use a test material to verify property changes before applying them globally.

πŸ“¦ Installation | πŸ“Œ Shader Property Support | πŸ›  API Reference

Clone this wiki locally