I assume you want to call function in game mode? There should be only one AGameMode and by spawning AGameMode somewhere you creating 2nd one and engine don’t expect two to exist in same time, thats why it may crash. Keep in mind that there class insistence already created by the engine and you can get them using already existing functions like:
()->GetAuthGameMode();
or
UGameplayStatics::GetGameMode(());
You should not create incenses of major game defining classes like AGameMode, APlayerController etc. and practically any other class based of AInfo, this is handled by the engine it self and those classes. By doing that you might only duplicating them and create dead objects which can mess up the engine work routine as it does not expect more manually created objects of those classes to exist.
Also keep in mind in multiplayer that AGameMode, APlayerController objects exists only on server side for security reasons (so user can’t modify them with memory modifiers). Anything they do in the server will be naturally applied to clients via actors they interact with.