Substrate-controlled nucleation of the magnetic phase transtition in nanostructures