This page contains information on how to get, set, and configure the render pipelineA series of operations that take the contents of a Scene, and displays them on a screen. Unity lets you choose from pre-built render pipelines, or write your own. More info
See in Glossary that Unity is currently using. The render pipeline that Unity is currently using is called the active render pipeline.
To render content, Unity can either use the Built-in Render Pipeline or a render pipeline based on the Scriptable Render Pipeline (SRP), which includes the Universal Render Pipeline (URP) and the High Definition Render Pipeline (HDRP).
To specify which Scriptable Render Pipeline Unity uses, you use Render Pipeline Assets. A Render Pipeline Asset tells Unity which SRP to use, and how to configure it. If you don’t specify a Render Pipeline Asset, Unity uses the Built-in Render Pipeline.
You can create multiple Render Pipeline Assets that use the same render pipeline, but with different configurations; for example, you can use different Render Pipeline Assets for different hardware quality levels. For a general introduction to Render Pipeline Assets, see Scriptable Render Pipeline introduction. For information on URP’s Render Pipeline Asset, see The Universal Render Pipeline Asset, and for HDRP’s Render Pipeline Asset, see The High Definition Render Pipeline Asset.
As soon as you change the active render pipeline in the Unity Editor or at runtime, Unity uses the new active render pipeline to render content. If you are in the Unity Editor, this includes the Game view, the Scene view, and previews for Materials in the Project panel and the Inspector.
When you change the active render pipeline, you must ensure that the assets and code in your project are compatible with the new render pipeline; otherwise, you might experience errors or unintended visual effects.
Settings in both Graphics Settings and Quality Settings determine the active render pipeline. In Graphics Settings, you configure the render pipeline that Unity uses by default. In Quality Settings, you can override the default render pipeline for a given quality level.
To get or set the default render pipeline, use Graphics Settings > Scriptable Render Pipeline Setting (or its equivalent API, GraphicsSettings.defaultRenderPipeline). To get or set the render pipeline that overrides the default for a given quality level, Quality Settings > Render Pipeline (or its equivalent API, QualitySettings.renderPipeline).
Unity determines the active render pipeline like this:
To get the active render pipeline in the Editor UI, you must check both the Graphics Settings and Quality Settings windows. For information on how to use these values to determine the active render pipeline, see Determining the active render pipeline.
To set the active render pipeline to the Built-in Render Pipeline, remove any Render Pipeline Assets from Graphics Settings and Quality Settings.
为此需要执行以下操作:
To set the active render pipeline to one that is based on SRP, tell Unity which Render Pipeline Asset to use as the default active render pipeline, and optionally which Render Pipeline Assets to use for each quality level.
为此需要执行以下操作:
In C# scripts, you can get and set the active render pipeline and receive a callback when the active render pipeline changes. You can do this in Edit Mode or Play Mode in the Unity Editor, or at runtime in your application.
要执行此操作,请使用以下 API:
The following example code shows how to use these APIs:
using UnityEngine;
using UnityEngine.Rendering;
public class ActiveRenderPipelineExample : MonoBehaviour
{
// In the Inspector, assign a Render Pipeline Asset to each of these fields
public RenderPipelineAsset defaultRenderPipelineAsset;
public RenderPipelineAsset overrideRenderPipelineAsset;
void Start()
{
GraphicsSettings.defaultRenderPipeline = defaultRenderPipelineAsset;
QualitySettings.renderPipeline = overrideRenderPipelineAsset;
DisplayCurrentRenderPipeline();
}
void Update()
{
// When the user presses the left shift key, switch the default render pipeline
if (Input.GetKeyDown(KeyCode.LeftShift)) {
SwitchDefaultRenderPipeline();
DisplayCurrentRenderPipeline();
}
// When the user presses the right shift key, switch the override render pipeline
else if (Input.GetKeyDown(KeyCode.RightShift)) {
SwitchOverrideRenderPipeline();
DisplayCurrentRenderPipeline();
}
}
// Switch the default render pipeline between null,
// and the render pipeline defined in defaultRenderPipelineAsset
void SwitchDefaultRenderPipeline()
{
if (GraphicsSettings.defaultRenderPipeline == defaultRenderPipelineAsset)
{
GraphicsSettings.defaultRenderPipeline = null;
}
else
{
GraphicsSettings.defaultRenderPipeline = defaultRenderPipelineAsset;
}
}
// Switch the override render pipeline between null,
// and the render pipeline defined in overrideRenderPipelineAsset
void SwitchOverrideRenderPipeline()
{
if (QualitySettings.renderPipeline == overrideRenderPipelineAsset)
{
QualitySettings.renderPipeline = null;
}
else
{
QualitySettings.renderPipeline = overrideRenderPipelineAsset;
}
}
// Print the current render pipeline information to the console
void DisplayCurrentRenderPipeline()
{
// GraphicsSettings.defaultRenderPipeline determines the default render pipeline
// If it is null, the default is the Built-in Render Pipeline
if (GraphicsSettings.defaultRenderPipeline != null)
{
Debug.Log("The default render pipeline is defined by " + GraphicsSettings.defaultRenderPipeline.name);
}
else
{
Debug.Log("The default render pipeline is the Built-in Render Pipeline");
}
// QualitySettings.renderPipeline determines the override render pipeline for the current quality level
// If it is null, no override exists for the current quality level
if (QualitySettings.renderPipeline != null)
{
Debug.Log("The override render pipeline for the current quality level is defined by " + QualitySettings.renderPipeline.name);
}
else
{
Debug.Log("No override render pipeline exists for the current quality level");
}
// If an override render pipeline is defined, Unity uses that
// Otherwise, it falls back to the default value
if (QualitySettings.renderPipeline != null)
{
Debug.Log("The active render pipeline is the override render pipeline");
}
else
{
Debug.Log("The active render pipeline is the default render pipeline");
}
// To get a reference to the Render Pipeline Asset that defines the active render pipeline,
// without knowing if it is the default or an override, use GraphicsSettings.currentRenderPipeline
if (GraphicsSettings.currentRenderPipeline != null)
{
Debug.Log("The active render pipeline is defined by " +GraphicsSettings.currentRenderPipeline.name);
}
else
{
Debug.Log("The active render pipeline is the Built-in Render Pipeline");
}
}
}