To create a temporary texture in the render graph system, use the CreateTexture method of the render graph instance.
When you create a texture inside a render pass, the render graph system handles the creation and disposal of the texture. This process means the texture might not exist in the next frame, and other camerasA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary might not be able to use it. To make sure a texture is available across frames and cameras, refer to Use a texture in multiple render passes instead.
When the render graph system optimizes 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, it might not create a texture if the final frame doesn’t use the texture, to reduce the memory and bandwidth the render passes use.
In the RecordRenderGraph method of your ScriptableRenderPass class, follow these steps:
Create a TextureDesc object with the texture properties you need.
Use the CreateTexture method of the render graph instance to create a texture and return a texture handle.
For example, the following creates a texture the same size as the screen.
UniversalResourceData frameData = frameContext.Get<UniversalResourceData>();
TextureDesc textureDesc = frameData.activeColorTexture.GetDescriptor(renderGraph);
TextureHandle textureHandle = renderGraph.CreateTexture(textureDesc);
Note: Avoid using UniversalRenderer.CreateRenderGraphTexture, because it can introduce subtle bugs.
The render graph system manages the lifetime of textures you create with CreateTexture, so you don’t need to manually dispose of the memory they use when you’re finished with them.
You can use the Render Graph Viewer window to inspect how URP handles load actions on textures. This is useful to debug your results and confirm whether Unity clears, preserves, or discards a texture.
Note: The clear parameter and the AccessFlags value affect how URP sets the load action for a texture. This can impact rendering results:
clear is true and you use AccessFlags.WriteAll, the load action is DontCare, not Clear. This is because Unity assumes you’re overwriting the entire texture, so it skips clearing the texture to optimize performance.clear is false and you use AccessFlags.Write, the load action is Clear. This is because Unity clears the texture automatically to avoid rendering artifacts if you only write part of the texture. To skip Unity clearing the texture, use AccessFlags.WriteAll to explicitly tell Unity you’re writing the full texture.The following Scriptable Renderer Feature contains an example render pass that creates a texture and clears it to yellow. For more information about adding the render pass to the render pipeline, refer to Inject a pass using a Scriptable Renderer Feature.
Use the Frame Debugger to check the texture the render pass adds.
using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering.RenderGraphModule;
using UnityEngine.Rendering;
public class CreateYellowTextureFeature : ScriptableRendererFeature
{
    CreateYellowTexture customPass;
    public override void Create()
    {
        customPass = new CreateYellowTexture();
        customPass.renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing;
    }
    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {
        renderer.EnqueuePass(customPass);
    }
    class CreateYellowTexture : ScriptableRenderPass
    {
        class PassData
        {
            public TextureHandle cameraColorTexture;
        }
        public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameContext)
        {
            using (var builder = renderGraph.AddRasterRenderPass<PassData>("Create yellow texture", out var passData))
            {
                // Get the frame data
                UniversalResourceData frameData = frameContext.Get<UniversalResourceData>();
                // Create texture properties that match the screen size
                TextureDesc textureDesc = frameData.activeColorTexture.GetDescriptor(renderGraph);
                textureDesc.msaaSamples = MSAASamples.None;
                // Create a temporary texture
                TextureHandle texture = renderGraph.CreateTexture(textureDesc);
                // Set the texture as the render target
                builder.SetRenderAttachment(texture, 0, AccessFlags.Write);
    
                // Make sure the render graph system keeps the render pass, even if it's not used in the final frame.
                // Don't use this in production code, because it prevents the render graph system from removing the render pass if it's not needed.
                builder.AllowPassCulling(false);
                builder.SetRenderFunc(static (PassData data, RasterGraphContext context) => ExecutePass(data, context));
            }
        }
        static void ExecutePass(PassData data, RasterGraphContext context)
        {          
            // Clear the render target to yellow
            context.cmd.ClearRenderTarget(true, true, Color.yellow);            
        }
    }
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
            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.