Object not reappearing when visible

I have a object with mesh renderer. I have this script attached to it:

this.gameObject.SetActive( m_Renderer.isVisible );

Object does disappear when is not seen by camera. But when it should be visible again it doesnt work. This script works just fine with objects with sprite renderer. It just doesnt work with mesh renderer for some reason.

Can someone help me with it?

The m_Renderer.isVisible property is designed to work with SpriteRenderers, which are typically used for 2D objects, and it determines visibility based on whether the renderer’s sprite is visible in any camera’s view. This is a simplified check that works well for 2D elements.ble in any camera’s view. This is a simplified check that works well for 2D elements.

// Assuming you have a reference to the MeshRenderer
MeshRenderer meshRenderer;

private void Update()
    // Check if the object should be visible based on your criteria.
    bool shouldBeVisible = ShouldObjectBeVisible();

    // Set the GameObject's active state based on the visibility criteria.

private bool ShouldObjectBeVisible()
    // Implement your logic to determine when the object should be visible.
    // This could be based on distance from the camera, game state, or any other criteria.
    // Return true if it should be visible, false otherwise.
    // Example:
    // return Vector3.Distance(transform.position, Camera.main.transform.position) < someDistanceThreshold;