A previously fixed problem with a seperate Orthographic camera is not causing a problem again and idk how to fix it

Hi, I am a somewhat experienced unity user but I have not a whole lot of experience using cameras. I usually just have one per scene but the game I’m making, which has some stealth features, needs more than one. I am currently using this system to make it so the player can detect how much light is currently on them so they can sneak around.

The tl;dr of it is that it has a separate camera setup looking at a quad placed in the player and detects how much light is in view. The tutorial is a bit outdated though and when I followed it, it gave me the problem I’m having now. I fixed it by making the camera Orthographic. Recently I have no idea what happened but I changed something so the problem came back up again where when both cameras were on, the screen looked like this:

The screen is supposed to look like this

The settings for the two camera (The main player camera is above, the camera used for shadow detection is bellow)


Does anyone know enough about cameras to help me be able to have both camera on at the same time but also have the player camera be unaffected by the light detection one?

Problem solved?
I did some more testing and I think its just the code from the tutorial I’m using that’s a bit buggy. I just trial and error’d commented out code until both the camera and the light detection system worked. It still doesn’t explain why it was working fine before with the same code or why doing this would even screw something up. If anyone also has any insights on this that would still be appreciated in case this issue crops up again. The “m_camLightScan.targetTexture = null;” line in particular worked when commenting it out but I’m still somewhat at a loss as to why.

public class LightDetection : MonoBehaviour
{
    [Header("Settings")]
    [Tooltip("The camera who scans for light.")]
    public Camera m_camLightScan;
    [Tooltip("Show the light value in the log.")]
    public bool m_bLogLightValue = false;
    [Tooltip("Time between light value updates (default = 0.1f).")]
    public float m_fUpdateTime = 0.1f;

    public static float s_fLightValue;

    private const int c_iTextureSize = 1;

    private Texture2D m_texLight;
    private RenderTexture m_texTemp;
    private Rect m_rectLight;
    private Color m_LightPixel;

    private void Start()
    {
        StartLightDetection();
    }

    /// <summary>
    /// Prepare all needed variables and start the light detection coroutine.
    /// </summary>
    private void StartLightDetection()
    {
        m_texLight = new Texture2D(c_iTextureSize, c_iTextureSize, TextureFormat.RGB24, false);
        m_texTemp = new RenderTexture(c_iTextureSize, c_iTextureSize, 24);
        m_rectLight = new Rect(0f, 0f, c_iTextureSize, c_iTextureSize);

        StartCoroutine(LightDetectionUpdate(m_fUpdateTime));
    }

    /// <summary>
    /// Updates the light value each x seconds.
    /// </summary>
    /// <param name="_fUpdateTime">Time in seconds between updates.</param>
    /// <returns></returns>
    private IEnumerator LightDetectionUpdate(float _fUpdateTime)
    {
        while (true)
        {
            //Set the target texture of the cam.
            m_camLightScan.targetTexture = m_texTemp;
            //Render into the set target texture.
            m_camLightScan.Render();

            //Set the target texture as the active rendered texture.
            RenderTexture.active = m_texTemp;
            //Read the active rendered texture.
            m_texLight.ReadPixels(m_rectLight, 0, 0);

            //Reset the active rendered texture.
            RenderTexture.active = null;
            //Reset the target texture of the cam.
            // I have no idea why but when this line of code is uncommented it breaks the camera so for the time being don't touch it
            //m_camLightScan.targetTexture = null;

            //Read the pixel in middle of the texture.
            m_LightPixel = m_texLight.GetPixel(c_iTextureSize / 2, c_iTextureSize / 2);

            //Calculate light value, based on color intensity (from 0f to 1f).
            s_fLightValue = (m_LightPixel.r + m_LightPixel.g + m_LightPixel.b) / 3f;

            if (m_bLogLightValue)
            {
                Debug.Log("Light Value: " + s_fLightValue);
            }

            yield return new WaitForSeconds(_fUpdateTime);
        }
    }
}