An answer I haven’t seen yet is UV protection. Direct sunlight irradiates cells, which can damage DNA. If that damaged DNA is in a reproductive part like a spore, the offspring can have trouble surviving. This is doubly important in some species of fungus with haploid spores, since they only have one of each chromosome. Diploid cells have matching pairs of chromosomes which act as backups to help survive this kind of damage.
With spores hidden under the cap, you reduce the damage caused by direct sunlight. This lets the mushrooms survive in environments with harsher sun.
Latest Answers