Add controls to the Rendering Debugger in URP
Customise the Rendering Debugger window with your own controls and scripts, to visualize your project's lighting, rendering or material properties.
Read time 3 minutesLast updated 20 days ago
You can customise the Rendering Debugger window with your own controls and scripts, to visualize your project's lighting, rendering or Material properties.
The Rendering Debugger window contains multiple tabs ('panels'). When you select a panel, the window displays one or more controls ('widgets').
To create a widget and add it to a new panel, do the following:
- Create a script that uses to include the
using UnityEngine.Rendering;namespace.UnityEngine.Rendering - Create a widget by creating an instance of a child class of DebugUI.Widget, for example .
DebugUI.Button - In the widget, implement the callback, which Unity calls when you change the value in the widget.
onValueChanged - Create a panel using DebugUI.instance.GetPanel.
- Add the widget to an array.
- Add the widget array to the list of children in the panel.
If you add 2 or more widgets to the array, the panel displays the widgets in the same order as the array.
The following code sample creates and adds a widget that enables or disables the main directional light:
using UnityEngine;using UnityEngine.Rendering;using System.Collections.Generic;using System.Linq;[ExecuteInEditMode]public class CustomDebugPanel : MonoBehaviour{ static bool lightEnabled = true; void OnEnable() { // Create a list of widgets var widgetList = new List<DebugUI.Widget>(); // Add a checkbox widget to the list of widgets widgetList.AddRange(new DebugUI.Widget[] { new DebugUI.BoolField { displayName = "Enable main directional light", tooltip = "Enable or disable the main directional light", getter = () => lightEnabled, // When the widget value is changed, change the value of lightEnabled setter = value => lightEnabled = value, // Run a custom function to enable or disable the main directional light based on the widget value onValueChanged = DisplaySunChanged }, }); // Create a new panel (tab) in the Rendering Debugger var panel = DebugManager.instance.GetPanel("My Custom Panel", createIfNull: true); // Add the widgets to the panel panel.children.Add(widgetList.ToArray()); } // Remove the custom panel if the GameObject is disabled void OnDisable() { DebugManager.instance.RemovePanel("My Custom Panel"); } // Enable or disable the main directional light based on the widget value void DisplaySunChanged(DebugUI.Field<bool> field, bool displaySun) { Light sun = FindObjectsOfType<Light>().Where(x => x.type == LightType.Directional).FirstOrDefault(); if (sun) sun.enabled = displaySun; }}
Add the script to a GameObject. You should notice a new My Custom Panel panel in the Rendering Debugger window.
Add a control to an existing panel
To fetch an existing panel, use with the panel name. Set to , so you don't accidentally create a new panel if the name doesn't match an existing panel.
DebugManager.instance.GetPanelcreateIfNullfalseThe following code sample fetches the panel from the code sample above:
var panel = DebugManager.instance.GetPanel("My Custom Panel", createIfNull: false);
You shouldn't add widgets to URP's built-in Rendering Debugger panels.
Add a container
You can use containers to display groups of widgets together.
- Create a container using one of the child classes of DebugUI.Container, for example .
DebugUI.Foldout - Add a widget array using the container's method.
Add
The following code sample creates a collapsible container that contains 2 checkboxes:
using UnityEngine;using UnityEngine.Rendering;using System.Collections.Generic;[ExecuteInEditMode]public class CustomDebugPanelWithContainer : MonoBehaviour{ void OnEnable() { // Create a list of widgets var widgetList = new List<DebugUI.Widget>(); // Add 2 checkbox widgets to the list of widgets widgetList.AddRange(new DebugUI.Widget[] { new DebugUI.BoolField { displayName = "Visualisation 1", }, new DebugUI.BoolField { displayName = "Visualisation 2", }, }); // Create a container var container = new DebugUI.Foldout { displayName = "My Container" }; // Add the widgets to the container container.children.Add(widgetList.ToArray()); // Create a new panel (tab) in the Rendering Debugger var panel = DebugManager.instance.GetPanel("My Custom Panel With Container", createIfNull: true); // Add the container to the panel panel.children.Add(container); }}