I made this function in my own AGameMode class (all you need to do for that is just add c++ class from the editor and pick game mode, it makes a blank class for you to use that extends the base gamemode class).
Try not to modify core unreal engine classes