We establish a transfer of unitarity for a Bernstein component of the category of smooth representations of a reductive $p$-adic group to the associated Hecke algebra, in the framework of the theory of types, whenever the Hecke algebra is an affine Hecke algebra with geometric parameters, in the sense of Lusztig (possibly extended by a group of automorphisms of the root datum). It is known that there is a large class of such examples (detailed in the paper). As a consequence, we establish relations between the unitary duals of different groups, in the spirit of endoscopy.