You can do it that way, but in general it’s bad practice to reference blueprint assets from code (you should only really do it as a last resort).
A better approach is to create a Blueprint of the GameMode, then in that Blueprint you can set your custom player controller. Blueprints that are data-only assets have zero performance overhead, and you get all the benefits of nicely managed references etc.