Home Integration Usage API FAQ URP14 # URP 14 Integration Guide For some yet unknown reason URP version 14 does not work directly with Metal Screen Recorder like all other renderers and older URP versions do. Luckily this can be worked around by using an additional overlay camera and doing a custom integration. ## Required scripts To follow this guide you should first save the below custom integration scripts in to your projects. ### UrpCameraRecorder.cs ``` using UnityEngine; using UnityEngine.Rendering; using pmjo.NextGenRecorder; [RequireComponent(typeof(Camera))] public class UrpCameraRecorder : Recorder.VideoRecorderBase { public static UrpCameraRecorder Instance; private Camera m_RecordedCamera; void Awake() { Instance = this; Recorder.VerticalFlip = false; Recorder.ColorSpace = ColorSpace.Linear; m_RecordedCamera = GetComponent<Camera>(); } public void Configure(CommandBuffer commandBuffer) { if (!Application.isPlaying) { return; } CommandBufferCaptureMetalRenderTarget(commandBuffer); } public Camera RecordedCamera { get { return m_RecordedCamera; } } } ``` ### CameraRecordingPass.cs ``` using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; public class CameraRecordingPass : ScriptableRendererFeature { class CustomRenderPass : ScriptableRenderPass { private CommandBuffer m_CommandBuffer; public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor) { } public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { if (UrpCameraRecorder.Instance == null || UrpCameraRecorder.Instance.RecordedCamera != renderingData.cameraData.camera) { return; } if (m_CommandBuffer == null) { m_CommandBuffer = new CommandBuffer(); UrpCameraRecorder.Instance.Configure(m_CommandBuffer); } context.ExecuteCommandBuffer(m_CommandBuffer); } public override void FrameCleanup(CommandBuffer cmd) { } } CustomRenderPass m_ScriptablePass; public override void Create() { m_ScriptablePass = new CustomRenderPass(); m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRendering; } public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) { renderer.EnqueuePass(m_ScriptablePass); } } ``` ## Recording the screen with the UI By default there will be just a single camera in an URP scene. To be able to record the screen in URP 14 you must add an additional camera that will be used for rendering the UI while the Main Camera will continue rendering the 3d. a) Add a new camera. Set name to "UI Camera", Render Type to Overlay and Culling Mask to UI only. Remove the Audio Listener from the UI Camera if it has one and next drop the UrpCameraRecorder component (above) on to the camera. ![Metal Screen Recorder](img/urp14_ui_camera.png "pmjo's Next Gen Recorder") b) Remove the UI from the Main Camera Culling Masks and add UI Camera to the Camera stack. This will change the rendering so that 3d will be rendered using the Main Camera and UI will be rendered with the UI Camera. ![Metal Screen Recorder](img/urp14_main_camera.png "pmjo's Next Gen Recorder") c) Next you should add Camera Recording Pass to all of your renderers which by default are stored in the project Settings folder. Open up a renderer (for example URP-Balanced-Renderer) and add the Camera Recording Pass as the last item in Renderer Features list. Do the same for the other renderers you have incase you want to record them. Notice that by default iOS uses different renderer than Mac. ![Metal Screen Recorder](img/urp14_screen_recording.png "pmjo's Next Gen Recorder") d) Done. For testing out the recording you can implement your own recording logic or just drop the SimpleRecorder prefab to your scene like in above screenshot. ## Recording the screen without the UI To record the 3d only you will need to add one more camera to the above created custom integration. This camera will not actually render anything, it will be used for recording only. a) Start by removing the Urp Camera Recorder from your UI Camera. ![Metal Screen Recorder](img/urp14_ui_camera_no_ui.png "pmjo's Next Gen Recorder") b) Then create a new camera. Set name to "Recording Camera", Render Type to Overlay and remove all items from the Culling Mask so it does not really render anything. Then remove the Audio Listener if it has one and drop the UrpCameraRecorder component on to the camera. ![Metal Screen Recorder](img/urp14_recording_camera.png "pmjo's Next Gen Recorder") c) Finally add the newly created Recording Camera to the Main Camera's Camera Stack BEFORE the UI Camera. ![Metal Screen Recorder](img/urp14_camera_stack_no_ui.png "pmjo's Next Gen Recorder") d) Done.