Control material properties in the Inspector window
Use the MaterialPropertyDrawer API or a custom editor to expose material properties in the Inspector window of a material.
Read time 2 minutesLast updated 24 days ago
In the Unity Editor, you can control how material properties appear in the Inspector window. The easiest way to do this is using a MaterialPropertyDrawer.
Use a custom editor
Use custom editors to display data types that Unity can't display using its default material Inspector, or to define custom controls or data validation.
In ShaderLab, you can assign a custom editor for all render pipelines. To do this, you can place a block inside a block. You can also assign different custom editors for render pipelines based on the Scriptable Render Pipeline by placing a block inside a block. If your code contains both a and block, the render pipeline specific one overrides the one.
CustomEditorShaderCustomEditorForRenderPipelineShaderCustomEditorCustomEditorForRenderPipelineCustomEditorCreate a custom editor class for a shader asset
To define a custom editor for shader assets that represent a given Shader object, you create a script that inherits from the ShaderGUI class. Place your script in a folder named Editor, in your Assets folder.
The script should follow this format:
using UnityEditor;public class ExampleShaderGUI : ShaderGUI { public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] properties) { // Custom code that controls the appearance of the Inspector goes here base.OnGUI (materialEditor, properties); }}
Enable the default custom editor
This example code demonstrates the syntax for specifying a default custom editor for a shader asset using the block, and then specifying two additional custom editors for specific Render Pipeline Assets using the block.
CustomEditorCustomEditorForRenderPipelineShader "Examples/UsesCustomEditor"{ // The Unity Editor uses the class ExampleCustomEditor to configure the Inspector for this shader asset CustomEditor "ExampleShaderGUI" CustomEditorForRenderPipeline "ExampleRenderPipelineShaderGUI" "ExampleRenderPipelineAsset" CustomEditorForRenderPipeline "OtherExampleRenderPipelineShaderGUI" "OtherExampleRenderPipelineAsset" SubShader { // Code that defines the SubShader goes here. Pass { // Code that defines the Pass goes here. } }}