Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Resolved Incredibly strange behaviour of the renderer?

Discussion in '2D Experimental Preview' started by ThundThund, Apr 22, 2021.

  1. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    225
    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:
    1. I create and store in a pool a bunch of sprites with custom material / shader. They are bullets of a weapon.
    2. I shoot those bullets, activating the objects and moving them along a straight line.
    3. When a bullet hits a surface or moves too far, they are disabled and put back in the pool.
    4. 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.
     
    Last edited: Apr 22, 2021
  2. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    225
    Another video, now zooming out the Scene view camera:
     
  3. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    225
    Do you know what's even funnier? This is what RenderDoc captures, bullets are visible. However, Unity does not display them.
    upload_2021-4-22_12-49-38.png
     
  4. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    225
    The Unity's Frame debugger does not include the bullets in the render process though, as far as I can see.
     
  5. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    225
    The OnWillRenderObject is not called for the bullets, until I move the Scene view camera to the proper position.
     
  6. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    225
    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.
     
  7. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,175
    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.
     
unityunity