I have a problem with camera unloading objects

I have a problem with the camera.
I have a sensor behind the player that’s looking for a collision with a wall.
When that happens, the camera moves towards the player because I don’t want it to clip inside the wall.

This all works but at a certain distance of 6+ units when the collision happens, the camera moves towards the player like it should and then returns back and then again back to the player.

This doesn’t happen when I’m close to the wall only with 6+ units away from the player.

When I set the camera further away, this doesn’t happen and it works as it should but the camera is too far from the player.

If I’m not wrong, this looks like the camera unloads the objects behind it at a certain distance.
Can you set the unloading distance?

Have the camera raycast check to see if the hit object is the player or not. You can do this by checking IF NOT player on a game-property, object name, material or more. That way the zooming only happens if the object between the camera and the player is actually not the player itself.

Thank you for your suggestion.
So I should make a ray cast from the camera towards the player?

Yes. I originally assumed you had been using that as your camera, but there’s not really any difference if you used another object or your camera, as long as your raycast is checking if the hit object is the player.