URP ScriptableRenderPass and Render Target restoration

Hey everybody,

I have a question regarding CommandBuffer.SetRenderTarget and how it interacts with ScriptableRenderPasses in URP. According to the official CommandBuffer.SetRenderTarget docs:
You do not explicitly need to preserve active render targets during command buffer execution (current render targets are saved & restored afterwards).

This behaviour is somehow not consistent with ScriptableRenderPasses. As an example: if I call SetRenderTarget in a CommandBuffer for ScriptableRenderPass that executes AfterRenderingOpaques, the RenderTarget is not restored afterwards and the skybox will be rendered to the wrong render target. If this is a bug, I can submit a bug report.

I tried searching for an answer for this behaviour, but didn’t find anything useful. Is this behaviour documented better somewhere? Can somebody from the Unity dev team explain what exactly is happening here.

(Sorry for the necro-post, but this is the top hit for this question…)

Answer: Don’t use CommandBuffer.SetRenderTarget, instead call “ConfigureTarget” inside your Configure function:

Yes, I had to search for AGES for the answer to this problem as well.

1 Like