Phenotypic plasticity, the ability of a genotype to produce multiple phenotypes in response to the environment, is a widespread phenomenon that is often adaptive, helping organisms optimally match traits to a heterogenous environment. Recent research on adaptive plasticity has focused on considering the inherent complexity of the real world; plastic traits may be induced by multiple environmental cues and may be under several selective pressures. Thus, it is critical to consider multiple dimensions of environmental variation and the costs and benefits of plastic traits across these environments. We investigated melanin pigmentation plasticity in the white-lined sphinx moth, Hyles lineata, which displays a high degree of melanin plasticity during the late larval instars, induced by multiple cues. We integrated environmental complexity by exploring two possible adaptive roles of melanin plasticity- thermoregulation and desiccation prevention. We also considered variation in diet quality to test for constraints on, or costs of, producing melanin. While we did not find support for a role of melanin in desiccation prevention, we did find evidence that melanin plasticity is adaptive in thermally variable environments. More melanic larvae outperform less melanic larvae in cold environments, although they do not suffer costs in warm environments. However, we found that melanin pigmentation during the larval stage can be costly because it trades off with other important traits including immunity and adult pigmentation. Considering several dimensions of the environment and multiple roles of melanin provides important insights into the ultimate reasons for the evolution of melanin plasticity.