Search Unity

Question Shader Behaves Differently In Standalone Windows build?

Discussion in 'General Graphics' started by AronTD, Sep 5, 2022.

  1. AronTD

    AronTD

    Joined:
    Aug 31, 2013
    Posts:
    22
    Howdy, I'm seeing some odd behavior after I build and run my game. I have two functions:

    Code (CSharp):
    1. CameraShake(Time.deltaTime);
    Code (CSharp):
    1.         public void SetLightPosition(int lightIndex, Vector2 worldPosition)
    2.         {
    3.             Vector2 screenPosition = Camera.main.WorldToViewportPoint(worldPosition);
    4.             _applyToTexture(_positionsTexture, lightIndex, new Color(screenPosition.x, screenPosition.y, 0));
    5.         }
    CameraShake moves the camera around a bit and SetLightPosition sets some data in a texture that's used by a shader. I call CameraShake before SetLightPosition.

    In the editor, everything behaves as expected. When the camera shakes, the lighting from the shader lines up properly.
    upload_2022-9-4_19-57-46.png

    However, if I run the standalone windows build I get this:
    upload_2022-9-4_19-59-10.png

    What could be causing this? Is this a bug?

    The shader is made with ShaderGraph and uses a custom function. I'm using URP.
     
    Last edited: Sep 5, 2022
  2. AronTD

    AronTD

    Joined:
    Aug 31, 2013
    Posts:
    22
    SOLVED!

    I had two cameras in the scene and Camera.main was referencing a different camera in the editor vs. in my build.
    Thus, the build was moving the wrong camera (because for whatever reason unity decides to change how Camera.main functions in a build?).
     
    Last edited: Sep 5, 2022