OnRenderImage() possibly didn't write anything to the destination texture!

So lately I’ve been getting this “OnRenderImage() possibly didn’t write anything to the destination texture!” warning every time I start up my app. It’s a one time warning (thankfully) so it doesn’t spam me or anything, but I hate seeing warnings for any reason though.

What exactly triggers this warning? What are the conditions that would cause this warning to appear?

It first appeared when I decided to do a hack to work around the VR showDeviceView limitation described in a thread I posted earlier: Any way to get VRSettings.showDeviceView to render into a Render Texture? - Unity Engine - Unity Discussions

The code sorta looks like this:

  public class VRCamera : MonoBehaviour
   {
     private Camera _camera;
     private int _frameCount;

     public RenderTexture MirrorTexture { get; private set; }

     void Awake()
     {
       _camera = GetComponent<Camera>();
       MirrorTexture = new RenderTexture(_camera.pixelWidth, _camera.pixelHeight, 0);
     }

     private void OnRenderImage(RenderTexture source, RenderTexture destination)
     {
       Graphics.Blit(source, destination);

       if (++_frameCount % 2 == 0)
       {
         Graphics.Blit(source, MirrorTexture);
       }
     }
   }

If I take out the second Blit, the warning goes away. Otherwise I still get the warning even if I do the blit every frame, every other frame (for left eye only), or whatever.

2 Likes

i had the same issue with u.
i solved like this…

1 Like

I somewhat followed this suggestion on a related script. The error disappeared alright but the effect I wanted initially did not also work. This may be a bug in Unity’s engine itself as reported here.

1 Like

From https://docs.unity3d.com/Manual/PostProcessingWritingEffects.html

“When OnRenderImage finishes, Unity expects that the destination render texture is the active render target. Generally, a Graphics.Blit or manual rendering into the destination texture should be the last rendering operation.”

So your last blit should use the destination texture.

if for whatever reason it’s inconvenient to have the destination texture be the target of the final blit, simply calling

Graphics.SetRenderTarget(destination);

seems to fix it