Search Unity

_Time built-in shader variable is not updated when a scene does not have a camera

Discussion in 'Shaders' started by T5Shared, Oct 5, 2020.

  1. T5Shared

    T5Shared

    Joined:
    Oct 19, 2018
    Posts:
    152
    Hi everyone,

    I noticed today that the time (using built-in shader variable _Time.y) in my UI shader is not updating, unless I either put a camera in the scene, or have the Scene tab open in the Unity Editor (which I guess counts as a camera). The Scene only contains UI, so I never added a camera. I tried this in Unity 2018 and 2020. Is this is bug, or intended behaviour?

    Thanks,
    Matt
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    You still need a camera if you want the UI to render in build/game view though... If nothing is actually being rendered then the rendering system isn't receiving calls to update GPU global values.
     
  3. T5Shared

    T5Shared

    Joined:
    Oct 19, 2018
    Posts:
    152
    Um, no. I have a published game with multiple scenes that have no explicit camera (i.e. a GameObject with a Camera Component) in them, and everything works fine. Until I wanted to do some UI shader effects yesterday.
     
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Do you mean additive scenes that don't have a camera but just a main scene that has a camera? Because I wasn't implying you couldn't have multiple scenes loaded that don't have a camera.
    If your game is just purely using the UI system... well that's intended behavior apparently if there are no cameras to trigger the update of those shader values.

    https://issuetracker.unity3d.com/is...updated-when-there-isnt-a-camera-in-the-scene

    So I'd probably just ensure you have an orthographic camera that your canvases use instead, completely avoiding the problem, otherwise have to figure out another workaround that works for your situation.
     
    T5Shared likes this.
  5. T5Shared

    T5Shared

    Joined:
    Oct 19, 2018
    Posts:
    152
    Sorry, I meant 'multiple scenes' as in different scenes that are not loaded at the same time. So I have multiple occurrences of a single scene with only UI, and no camera. Like you are suggesting, adding a camera is a quick workaround for the problem, so I have done that for now.

    And cheers for linking the original issue tracker bug. I searched for this for a bit, but could not find it. I would say that this shows that it is *not* intended behavior though. Just too hard to fix. Since Unity 5...

    Thanks for the feedback!