  We introduce a switching operation, inspired by the Godsil-McKay switching,
in order to obtain pairs of $G$-cospectral gain graphs, that are gain graphs
cospectral with respect to every representation of the gain group $G$. For
instance, for two signed graphs, this notion of cospectrality is equivalent to
the cospectrality of their signed adjacency matrices together with the
cospectrality of their underlying graphs. Moreover, we introduce another more
flexible switching in order to obtain pairs of gain graphs cospectral with
respect to some fixed unitary representation. Many existing notions of spectrum
for graphs and gain graphs are indeed special cases of these spectra associated
with particular representations, therefore our construction recovers the
classical Godsil-McKay switching and the Godsil-McKay switching for signed and
complex unit gain graphs. As in the classical case, not all gain graphs are
suitable for these switchings: we analyze the relationships between the
properties that make the graph suitable for the one or the other switching.
Finally we apply our construction in order to define a Godsil-McKay switching
for the right spectrum of quaternion unit gain graphs.
