Hello all! I need to do some rendering using the Graphics interface after the OnRenderImage() event, see Event Sequence: https://docs.unity3d.com/Manual/ExecutionOrder.html The only two options I could think of is doing my rendering in: Code (CSharp): OnGUI() or after: Code (CSharp): yield WaitForEndOfFrame() Both options are not ideal, OnGUI() creates lots of GC garbage (even with an empty implementation), and "yield WaitForEndOfFrame" is creating 40 bytes of garbage due to the required IEnumerator use for "yield" methods. I'm obsessed about GC impact on my project. I know 40 bytes is not a big deal, but humour my obsession for a moment, please. My entire project creates no garbage outside of initialization/shutdown code, with the exception of this OnGUI()/WaitForEndOfFrame() issue. Is there any other way of catching a render event after OnRenderImage()? Thank you.
try keeping WaitForEndOfFrame as a static variable and using that instead of creating a new one each time.
Yes I am doing that already. Here is my current setup: Code (CSharp): private WaitForEndOfFrame mEndOfFrameWait = new WaitForEndOfFrame(); private IEnumerator OnPostRender() { RenderUser(); // The yield causes some GC cost, 40 bytes in profiler. Not sure how to get around that... yield return mEndOfFrameWait; RenderPixelSurfaces(); } Even though I precreate WaitForEndOfFrame and reuse it, and I don't have any variables on the stack in OnPostRender() it still creates 40bytes of garbage. From my understanding this is because the callstack is retained after the "yield" statement and then reused when "yield" returns, the callstack would contain some minimal information including a class reference to mEndOfFrameWait, and thats where the 40 bytes comes from. I don't think there is any way around this with "yield". More on that here: https://stackoverflow.com/questions/35360100/how-does-gc-work-with-ienumerator-and-yield
There are some assets on the store that are designed to replace coroutines and implement them more efficiently, if those 40 bytes are big issue you could try one of them.
Interesting, I didn't think it was possible to replace WaitForEndOfFrame() but some assets do indeed claim to have figured it out. I'll dig around. Thank you!