RenderTexture.SetActive() huge profiler spikes

For some reason I am getting strange, unexplained spikes in RenderTexture.SetActive() in my game. It will be humming along taking up a reasonable amount of GPU time, and then suddenly spike up to 40ms for a single call (I’ve even seen 2 calls in one frame, one of which was under 1ms, the other over 40). Any idea what could cause such abnormally long call-times? I’m not doing anything fancy I can think of, and am not intentionally using RenderTexture at all (and I turned off all of the image effects on my camera that might be using it internal). Any ideas would be much appreciated, since right now I’m not even sure where to start looking.

-Sean

If you’re not using any render textures and still get spikes in the profiler, my theory is that it is actually the profiler graph that gives the spikes. The editor uses the Unity Engine as well, which means that to draw up the profiler graph it is using a render texture. I noticed this when I tried pulling the window slider up and down between CPU/GPU/Memory/Rendering etc, and saw how it started updating the graph more quickly while giving more render texture spikes. The same is true for the camera preview, which is also most likely a render texture.

My “theory” is:

it comes from GUI display activity in the Inspector and/or other windows in your Unity Editor that are updated while your game is running. I can reproduce a single spike if I just click into an Dropdown field (for example the one for a Camera “Clear Flags” in the Inspector and when I close the Dropdown I get a spike.

So to get rid of it: Enable “Maximize on Play” and also keep the “Stats” box closed. With this I do not get a single spike anymore. This also means that for a compiled exe you should not worry about those spikes.

Ben

Hey so after going down the rabbit hole a little, I came across this post:
http://forum.unity3d.com/threads/122684-Unity3D-working-slow-with-no-reason

Lead me to try switching off dynamic batching. That lead to all of that extra ‘Camera.ImageEffects’ GPU usage I was picking up in profiler disappearing. Unfortunately, then my draw calls skyrocketed.

Anyway, in my situation it seems the extra GPU from Camera.ImageEffects is all the dynamic batching happening.

Sorry if that’s a duh and you guys have a separate issue. But that’s the answer to what was plaguing me.

thanks!

I am getting that “problem” too and I am not using render textures but am using Beast and Light Probes. I am seeing its taking 33% of our rendering time in the GUI Profiler. Any ideas?

same here 70% just rendering difuse shaders and skinned meshes

same here 70% just rendering difuse, skinned meshes

we are having the same issue on our game, has anyone uncovered an answer to this yet?

Me too, even on an empty project with an empty scene with only one camera.
Up to 90ms spikes.

Same thing for me… profiler shows Camera.ImageEffects pulling 44.9% of Camera.Render even though I have no image effects on anything. Like a previous poster I also temporarily tried some effects on a camera, but have since removed them.

Any fix?

same here. one of our fifteen drawcalls is using 93 % of the total Camera.Render resulting in a very laggy feel on the galaxy and galaxy s2 but is for some reason unnoticeable on the asus transformer tablet.

It seems like calling SetActiveRecursively() on a GameObject with several mesh renderers attached to its children can also cause this spike. In that use case, turning off dynamic batching didn’t seem to make a difference.

Uhh… same here. I wish there was some way to reduce this, but I don’t know where to start.

Bens Reply (benni05) worked as a fix for me. i just maximized on play, ran it. stopped it, and un maximized on play. smooth as a whistle now.