I use camera stacking for my project. I have a second camera (for UI and other things that needs to get drawn over) that was set as an overlay camera in the stack.
I figured out what causes the GC. It is just simply having a second camera. Stacked or not, base or overlay does not matter. Strange thing is, it doesn’t even need to render anything. I turned off or disable everything on the camera and yet still GC shows up. Just being there is all it takes.
This is an empty project with the default URP work bench scene.
Am I doing something wrong here, how do I fix this?
Second, saying they opened “a backport case to the 2019.4 stream and hopefully:eyes:, it will be fixed in a separate package for the 2019.4 URP line (7.x.x)”.
Which is great but the world ‘hopefully’ worries me though and makes me wonder if there is a chance that this would not get fixed for those with 2019.4 and 7.x.x. Which would make it impossible to use the camera stack or multiple cameras in your project without significant performance consequences, especially for those with mobile or VR.
I will be happy to help test/troubleshoot any new packages, let me know!
Hello! I’ve had a separate thread open about this issue and entered that initial bug - it seems that half of the issue has been fixed, but the other half has not. I’m glad that someone else is experiencing this problem as I’ve been a little surprised that no one else has reported this as an issue!
Thank you! There will still be GC every frame in 2019.4 and URP 7.4.1 - SortCameras does not allocate GC, but GetCameras does when you have more than one camera.
It is indeed fixed! Not only that this also fixed an issue where material previews in the project view was not showing just -always showed black.
For a second there I thought my highly sophisticated, evil master plan to take over the VR world that entirely relied on camera stacking would crumble down to the ground, one spike at a time .
Phew! I feel better now! You guys are awesome! thank you!!!
I am not doing that thing (3 cameras outputting to one texture) you are doing with the render texture but I can confirm that I am not getting GC at all now. Have you tried outputting from only one camera to one render texture?
Good news that you’re no longer having this problem! For me, any combination of more than one camera (whether it’s base, overlay, rendertexture doesn’t seem to matter) creates GC allocs in the GetCameras() function called by the RenderPipelineManager for me, even with URP 7.4.1 and 2019.4.4. What does your camera setup look like, out of interest?
Depends on the scene I am in, but mostly its 1 base camera + one stacked camera for UI + another stacked for VR hands.
So if you were to start a brand new clean/empty project (with latest Unity 2019.4 and 7.41), and a scene that has only 2 cameras and nothing else, you still get GC?
I tested it out and yes there was GC alloc! Then, I removed your URP and reinstalled it 7.4.1 and then the GC disappeared. Maybe there was something left over from 7.3.x, just remove and reinstall and it should fix the issue.
Hm! I’ve tried uninstalling and reinstalling the URP package in that test project and still get the GC allocs, nothing changes for me whatsoever. Are you sure uninstalling didn’t remove the scriptable pipeline setting from the Graphics / Quality menu?
Could you do me a massive favor and maybe share a test project where you have multiple cameras with no GC allocs? I’m seeing something odd in the frame debugger where draw calls from separate cameras are appearing under one ‘Render Camera’, and I’m not sure if that’s intended behavior or not!
So here is the thing. I was trying it out again as I was getting you the project and gc alloc showed up again! I then deleted the library, reopen and let everything reimport again -everything was fine, no gc. Then I tried on my main project and even that had the issue. Then I closed and reopened it and gc problem was no longer there… It seems to show up time to time and I just can’t figure out what caused it. Then it was gone.
I am only guessing here but some thing causes this, probably because of something we are doing (to cameras?) and when you do a reimport () it fixes it.
@erikabar Is it possible for you to share with us what the cause and what the fix you guys did? is this somehow shader/material related? This way, instead of blindly trying everything, we can to narrow our focus to a certain area when we try to troubleshoot this?
@Unusual-Cadence attached is the project and it does not have the GC issue, well at least when I tested it. Also, fyi -I deleted the library folder to reduce the size of this attachment and it might take extra time to rebuild/reimport.
If you do manage to get the gc alloc again maybe share it again with Unity, so they can have a look at it? I hope we get to the bottom of this.