HI!
I have a need to get a component in GameMode (mostly to create widgets at different events), but I somehow think it doesn’t look right.
The screenshot shows what I mean:
In gamemode blueprint you can override function/event OnRestartPlayer, which is called right after spawning pawn for each player/controller. It is a generic event for both players and AIs, so it passes a generic Controller as parameter. You should first cast to PlayerController to check that it is the player, then use Controller->GetControlledPawn to access the Pawn, then get your component from there.
In terms of memory footprint no, PlayerController is a native class and native classes are all always loaded, always.
In terms of performance, eh.. It’s just a node. If you spawn hundreds of pawns per frame then sure, it may have an impact, although it would still be negligible compared to the overhead of pawns/controllers themselves.
Alternatively you can use Controller->IsPlayerController, but then you have to Branch, so that’s two nodes instead of one…
If you don’t use AIControllers, you can probably get rid of the check altogether.
GameMode always come before Character (since character is spawned by gamemode) so you can just do that in Character’s BeginPlay → Get Game Mode → call your function