Atomistic simulations have become increasingly central to many fields of science, from physics and materials science to chemistry and biology. Molecular dynamics plays a prominent role as a computational microscope that can integrate experiments and validate theoretical models. However, despite recent advances in software and hardware, many interesting processes are still out of its reach. The reason is that many systems exhibit long-lived (meta)stable states separated by high free-energy barriers. Examples of such rare events are phase transitions, chemical reactions, and biophysical processes. To lift this limitation, several enhanced sampling methods have been devised to enable the simulation of such processes. I will focus on a family of methods that rely on the identification of collective variables able to describe the transition between states. An external bias potential is then applied to the system as to accelerate the selected degrees of freedom, lowering the corresponding free energy barriers. However, the success of these methods depends on the identification of appropriate variables. I will describe how machine learning approaches can be used to find them in a data-driven way as well as improve the way the external potentials are constructed, thus extending the scope of advanced sampling simulations to more complex systems. Finally, I will discuss how these methods designed to augment sampling can also be very useful in constructing accurate machine-learned potentials for reactive events.