Enable and disable Renderer or Canvas not working

Every 5 seconds I need to take a photo and display it in the world. That part is working fine.
Once a photo is taken it need to disappear 1 second after. That’s where I’m stuck.
I’ve gotten it to disappear but then I cant get the new picture to reappear when its function is called again.

Any ideas?

I’ve tried:
m_CanvasRenderer.enabled = false;
m_CanvasRenderer.enabled = true;
m_Canvas = null;
m_Canvas.setActive(false);
m_Canvas.setActive(true);

public class PhotoCaptureExample : MonoBehaviour
{
    GestureRecognizer m_GestureRecognizer;
    GameObject m_Canvas = null;
    Renderer m_CanvasRenderer = null;
    PhotoCapture m_PhotoCaptureObj;
    CameraParameters m_CameraParameters;
    bool m_CapturingPhoto = false;
    Texture2D m_Texture = null;

    void Start()
    {
        Initialize();
        InvokeRepeating("TakePhoto", 5.0f, 5.0f);
        //StartCoroutine(TakePhoto());
    }

void TakePhoto()
    {
        if (m_CapturingPhoto)
        {
            return;
        }
        m_CapturingPhoto = true;
        m_PhotoCaptureObj.TakePhotoAsync(OnPhotoCaptured);
    }

    void OnPhotoCaptured(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
    {
       // m_CanvasRenderer.enabled = true;
  
        if (m_Canvas == null)
        {
 
            m_Canvas = GameObject.CreatePrimitive(PrimitiveType.Quad);
            m_Canvas.name = "PhotoCaptureCanvas";
            m_CanvasRenderer = m_Canvas.GetComponent<Renderer>() as Renderer;
            m_CanvasRenderer.material = new Material(Shader.Find("AR/HolographicImageBlend"));
        }

        Matrix4x4 cameraToWorldMatrix;
        photoCaptureFrame.TryGetCameraToWorldMatrix(out cameraToWorldMatrix);
        Matrix4x4 worldToCameraMatrix = cameraToWorldMatrix.inverse;

        Matrix4x4 projectionMatrix;
        photoCaptureFrame.TryGetProjectionMatrix(out projectionMatrix);

        photoCaptureFrame.UploadImageDataToTexture(m_Texture);
        m_Texture.wrapMode = TextureWrapMode.Clamp;

        m_CanvasRenderer.sharedMaterial.SetTexture("_MainTex", m_Texture);
        m_CanvasRenderer.sharedMaterial.SetMatrix("_WorldToCameraMatrix", worldToCameraMatrix);
        m_CanvasRenderer.sharedMaterial.SetMatrix("_CameraProjectionMatrix", projectionMatrix);
        m_CanvasRenderer.sharedMaterial.SetFloat("_VignetteScale", 1.0f);

        // Position the canvas object slightly in front
        // of the real world web camera.
        Vector3 position = cameraToWorldMatrix.GetColumn(3) - cameraToWorldMatrix.GetColumn(2);

        // Rotate the canvas object so that it faces the user.
        Quaternion rotation = Quaternion.LookRotation(-cameraToWorldMatrix.GetColumn(2), cameraToWorldMatrix.GetColumn(1));

        m_Canvas.transform.position = position;
        m_Canvas.transform.rotation = rotation;

        m_CapturingPhoto = false;

        float counter = 0; float target = 1;
        while (counter < target)
        {
            counter += Time.deltaTime;
        }
        // m_CanvasRenderer.enabled = false;
     
    }
}

First off, I admit though while I grasp the concept of most of your code, it’s over my head.
However, the ability to turn something on/off , visibility-wise should be pretty straight-forward.
Whatever you turned off (renderer/canvas), after the canvas check against null … turn it back on.
One note, though, is that you’re forcing a spin loop waiting for 1 second in your script. That’s a different issue, though.
If you turn on the renderer manually in the inspector on the second time through, is the photo there just invisible?

Get the component and just toggle that instead of the actual gameObject.

Just a note, when I was reading this post, it appeared as though he was creating a unique “canvas” improv.
I could be wrong or misunderstanding it, but his canvas is a quad…

You are correct.

My bad, early mornings…

All good… Confused me, too. I sometimes use ‘general’ names like that, but other times I can see how un-nice it can be when you go back/others read it :slight_smile:

I’m working in the hololens so I cant turn the renderer on manually in the inspector while running.
I thought it would be strait forward to turning something invisible then visible again.

Should be straight forward. Hope you figure it out.