docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Create a Render Pipeline Asset and Render Pipeline Instance in a custom render pipeline

    If you are creating your own render pipeline based on the Scriptable Render Pipeline (SRP), your Project must contain:

    • A script that inherits from RenderPipelineAsset and overrides its CreatePipeline() method. This script defines your Render Pipeline Asset.
    • A script that inherits from RenderPipeline, and overrides its Render() method. This script defines your Render Pipeline Instance, and is where you write your custom rendering code.
    • A Render Pipeline Asset that you have created from your RenderPipelineAsset script. This asset acts as a factory class for your Render Pipeline Instance.

    Because these elements are so closely related, you should create them at the same time.

    Creating a basic Render Pipeline Asset and Render Pipeline Instance

    The following example shows how to create a script for a basic custom Render Pipeline Asset that instantiates the Render Pipeline Instance, a script that defines the Render Pipeline Instance, and the Render Pipeline Asset itself.

    1. Create a C# script called ExampleRenderPipelineAsset.cs.

    2. Copy and paste the following code into the new script:

      using UnityEngine;
      using UnityEngine.Rendering;
      
      // The CreateAssetMenu attribute lets you create instances of this class in the Unity Editor.
      [CreateAssetMenu(menuName = "Rendering/ExampleRenderPipelineAsset")]
      public class ExampleRenderPipelineAsset : RenderPipelineAsset
      {
          // Unity calls this method before rendering the first frame.
          // If a setting on the Render Pipeline Asset changes, Unity destroys the current Render Pipeline Instance and calls this method again before rendering the next frame.
          protected override RenderPipeline CreatePipeline() {
              // Instantiate the Render Pipeline that this custom SRP uses for rendering.
              return new ExampleRenderPipelineInstance();
          }
      }
      
    3. Create a C# script called ExampleRenderPipelineInstance.cs.

    4. Copy and paste the following code into the new script:

      using UnityEngine;
      using UnityEngine.Rendering;
      using System.Collections.Generic;
      
      public class ExampleRenderPipelineInstance : RenderPipeline
      {
          public ExampleRenderPipelineInstance() {
          }
      
          protected override void Render (ScriptableRenderContext context, List<Camera> cameras) {
              // This is where you can write custom rendering code. Customize this method to customize your SRP.
          }
      }
      
    5. In the Project view, either click the add (+) button, or open the context menu and navigate to Create, and then choose Rendering > Example Render Pipeline Asset. Unity creates a new Render Pipeline Asset in the Project view.

    Creating a configurable Render Pipeline Asset and Render Pipeline Instance

    By default, a Render Pipeline Asset stores information about which Render Pipeline Instance to use for rendering, and the default Materials and Shaders to use in the Editor. In your RenderPipelineAsset script, you can extend your Render Pipeline Asset so that it stores additional data, and you can have multiple different Render Pipeline Assets with different configurations in your Project. For example, you might use a Render Pipeline Asset to hold configuration data for each different tier of hardware. The High Definition Render Pipeline (HDRP) and the Universal Render Pipeline (URP) include examples of this.

    The following example shows how to create a RenderPipelineAsset script that defines a Render Pipeline Asset with public data that you can set for each instance using the Inspector, and a Render Pipeline Instance that receives a Render Pipeline Asset in its constructor and uses data from that Render Pipeline Asset.

    1. Create a C# script called ExampleRenderPipelineAsset.cs.

    2. Copy and paste the following code into the new script:

      using UnityEngine;
      using UnityEngine.Rendering;
      
      // The CreateAssetMenu attribute lets you create instances of this class in the Unity Editor.
      [CreateAssetMenu(menuName = "Rendering/ExampleRenderPipelineAsset")]
      public class ExampleRenderPipelineAsset : RenderPipelineAsset
      {
          // This data can be defined in the Inspector for each Render Pipeline Asset
          public Color exampleColor;
          public string exampleString;
      
              // Unity calls this method before rendering the first frame.
             // If a setting on the Render Pipeline Asset changes, Unity destroys the current Render Pipeline Instance and calls this method again before rendering the next frame.
          protected override RenderPipeline CreatePipeline() {
              // Instantiate the Render Pipeline that this custom SRP uses for rendering, and pass a reference to this Render Pipeline Asset.
              // The Render Pipeline Instance can then access the configuration data defined above.
              return new ExampleRenderPipelineInstance(this);
          }
      }
      
    3. Create a C# script called ExampleRenderPipelineInstance.cs.

    4. Copy and paste the following code into the new script:

      using UnityEngine;
      using UnityEngine.Rendering;
      using System.Collections.Generic;
      
      public class ExampleRenderPipelineInstance : RenderPipeline
      {
          // Use this variable to a reference to the Render Pipeline Asset that was passed to the constructor
          private ExampleRenderPipelineAsset renderPipelineAsset;
      
          // The constructor has an instance of the ExampleRenderPipelineAsset class as its parameter.
          public ExampleRenderPipelineInstance(ExampleRenderPipelineAsset asset) {
              renderPipelineAsset = asset;
          }
      
          protected override void Render(ScriptableRenderContext context, List<Camera> cameras) {
              // This is an example of using the data from the Render Pipeline Asset.
              Debug.Log(renderPipelineAsset.exampleString);
      
              // This is where you can write custom rendering code. Customize this method to customize your SRP.
          }
      }
      
      
    5. In the Project view, either click the add (+) button, or open the context menu and navigate to Create, and then choose Rendering > Example Render Pipeline Asset. Unity creates a new Render Pipeline Asset in the Project view.


    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Creating a basic Render Pipeline Asset and Render Pipeline Instance
    • Creating a configurable Render Pipeline Asset and Render Pipeline Instance
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)