ATP is crucial for the function of both actin and myosin. In muscle contraction, ATP binds to the myosin head, leading to its detachment from actin. Hydrolysis of ATP then provides the energy required for the myosin head to return to its original position, ready to bind to actin again. This cycle is essential for continuous muscle contraction and relaxation.