Ecological generalism facilitates the evolution of sociality in snapping shrimps.