Antenna gain is directivity is a given direction.
One example where gain is not the only object is for antenna (typically parabolic dishes or segmented parabolic surface) used for space communication.
Signal to noise is the main object. Higher antenna gain does not alway mean better signal to noise. In space communication the main intended direction is usually pointing at a much lower noise temperature then terrestrial antennas that have the relatively hot earth in there field of view. The noise in the signal to noise ratio at the antenna output is KTB where K is Boltszmann constant (1.38x10^-23) times temperature of object that antenna is looking at, times bandwidth of channel.
Looking at the sky, the background noise temp can be quite low compared to earth, 5 deg K to 20 degs K compared to 290 degs K for earth. Highest gain on a dish is with full illumination across the surface of dish with minimal spillover on the edges. This uniform illumination, while giving the most directivity in a given direction, also comes with significant sidelobes. These sidelobes, although 10 db or more down in directivity gain compared to the main lobe, may be pointing at the hot 290 deg K earth. The antenna output noise floor is the summation of the main lobe at cold temp and all the sidelobes at whatever noise temp they happen to be pointing at. This can degrade the overall noise output of the antenna.
Most space communications antennas contour their illumination with drop off in intensity toward the edge of dish. This reduces directivity somewhat, yielding a broader main lobe but can greatly reduce the levels of sidelobes. The net result is a bit lower gain in the intended direction but much lower noise contributions from sidelobes, resulting in net better signal to noise ratio to the input to a receiver.