Long shader compile time for camera preview

This happens quite often when I select the camera object in a scene outside of play mode:

image

There’s three things that are surprising about this:
1: The camera is already drawing in the game view. It’s visible on the screen. Why does selecting the camera cause a bunch of shaders to be compiled? Does the little preview window in the scene view require completely different compile flags from the game view?
2: Why is this a blocking operation? Generally Unity is quite happy to just flashbang me with cyan shaders when they’re not compiled yet, but apparently if I click the camera this has to finish immediately?
3: Why does this happen so often? It might be that I just don’t select cameras so much, but I’d think all these variants were already in the cache. Does the camera preview’s shader variants not get cached?

Note, this is for sure caused by the camera preview in the scene view. If I hide it, none of these popups show up.

Some shaders (and some parts of rendering) disable async shader compilation. If you feel like it’s happening more than it should, would it be possible for you to submit a bug report so that relevant people can take a look at this?

Thanks for the reply.

I did report a bug, IN-84168. After looking at it, the problem is for sure that the preview camera has disabled async shader compilation. It’s still around in Unity 6 even though 6 has majorly refactored that window, so I assume the rendering part of it wasn’t touched.

It’s easy enough to repro with the URP sample scene as well, as long as you make sure to not look at the scene with the main cameras, so the shaders don’t go into cache.

1 Like