Hi everybody.
This is very strange and I’m not sure about whether I would be even able to reproduce it in a separated test project, I filed the bug 1330992. Watch the videos and images below please.
I’m using the 2D Renderer (URP 10.4), with Unity 2020.3.4 (also tried 2021.1.3).
This is what happens:
-
I create and store in a pool a bunch of sprites with custom material / shader. They are bullets of a weapon.
-
I shoot those bullets, activating the objects and moving them along a straight line.
-
When a bullet hits a surface or moves too far, they are disabled and put back in the pool.
-
If the EDITOR CAMERA (Scene view) views the bullets, they are rendered in the game view; otherwise, they are not.
Is there a bug in the camera culling algorithm? This happens in a release build too (bullets never get rendered).
How can the scene view affect what is rendered in the game view?
I can do whatever test you need, I don’t have a clue about what happens and how to solve it.
Another video, now zooming out the Scene view camera:
Do you know what’s even funnier? This is what RenderDoc captures, bullets are visible. However, Unity does not display them.
The Unity’s Frame debugger does not include the bullets in the render process though, as far as I can see.
The OnWillRenderObject is not called for the bullets, until I move the Scene view camera to the proper position.
Ok I think I found the problem, it’s not a Unity bug but a very tricky bug in my code. This is my assumption: The parameters of the shader used for drawing the lines were set in the OnWillRenderObject method, but the OnWillRenderObject method was not called because, I guess, the engine was not detecting any change, so it never set the parameters, etc. a vicious circle that made the bullets never be drawn. When I move the Scene view camera, it surely triggers the OnWillRenderObject to refresh whatever for all objects, it was a false clue. Another false clue was RenderDoc, which was rendering the bullets that were invisible in the editor. I will do a couple of tests tomorrow to be sure.
Humm… I also have some strange behavior with scene camera as well. In my case, ScreenToWorld API is broken if Scene View is showing in the editor. Why on earth SceneView visibility affecting main camera’s ScreenToWorld is just beyond me.