Hooking into the spawning process of a PlayerController
To hook into the process when the GameMode spawns you PlayerController you can override the following method in which the GameMode does the actual spawning:
/**
* Spawns a PlayerController at the specified location; split out from Login()/HandleSeamlessTravelPlayer() for easier overriding
*
* @param RemoteRole the role this controller will play remotely
* @param SpawnLocation location in the world to spawn
* @param SpawnRotation rotation to set relative to the world
*
* @return PlayerController for the player, NULL if there is any reason this player shouldn't exist or due to some error
*/
virtual APlayerController* SpawnPlayerController(ENetRole InRemoteRole, FVector const& SpawnLocation, FRotator const& SpawnRotation);
You can also override the following which will get called just after the GameMode has spawned a new PlayerController or after a SeamlessTravel (I recommend hooking your logic into the next function):
/**
* handles all player initialization that is shared between the travel methods
* (i.e. called from both PostLogin() and HandleSeamlessTravelPlayer())
*/
virtual void GenericPlayerInitialization(AController* C);
Hooking into the spawning process of your Pawn aka Character
The spawning process will try to spawn a Pawn aka Character at a given PlayerStart, you will be able to modify the final class implementing the following BlueprintNativeEvent.
/** returns default pawn class for given controller */
UFUNCTION(BlueprintNativeEvent, Category="Game")
UClass* GetDefaultPawnClassForController(AController* InController);
To override the base event just add the following to your header class and add the implementation into your cpp, remember to call the Super.
virtual UClass* GetDefaultPawnClassForController_Implementation(AController* InController) override;
And to control the actual spawning process you have to implement the following BlueprintNativeEvent (just add the implementation but not the declaration into your header):
/**
* @param NewPlayer - Controller for whom this pawn is spawned
* @param StartSpot - PlayerStart at which to spawn pawn
* @return a pawn of the default pawn class
*/
UFUNCTION(BlueprintNativeEvent, Category="Game")
APawn* SpawnDefaultPawnFor(AController* NewPlayer, class AActor* StartSpot);
To override the base event just add the following to your header class and add the implementation into your cpp, remember to call the Super.
virtual APawn* SpawnDefaultPawnFor_ImplementationAController* NewPlayer, class AActor* StartSpot) override;
You should be good to got with those hooks.