4.8 API Change to GetDefaultPawnClassForController

The virtual keyword has been removed from AGameMode::GetDefaultPawnClassForController

I used to have a custom implementation of this:



UClass* AGGameMode::GetDefaultPawnClassForController(AController* InController)
{
	// see if the pawn class is set on the controller, if so use the class it wants for the pawn
	IControllerInterface* c = Cast<IControllerInterface>(InController);
	if (c && c->DefaultPawnClassForController)
	{
		return c->DefaultPawnClassForController;
	}

	return Super::GetDefaultPawnClassForController(InController);
}


I use this to allow the AI and player controllers to spawn the pawn which suites them. How can I work around this?

Yeah quite a lot has changed in GameMode - including the removal of ‘DefaultTimer’ as well, and ‘ChoosePlayerStart’.

I’m waiting on 4.8’s full release to see how ShooterGame in particular gets around this stuff. I haven’t really had a chance to look at it yet.

Oh ****, we have overriden both of those functions and they are absolutely necessary for our game. I hope they offer us decent alternatives. This will be the second time they’ve completely revamped AGameMode. I hope it all works out well, and not like they forgot to make stuff virtual like they did in 4.7, which will only be fixed in 4.8.

You should raise your concern on the 4.8 Preview dedicated page in order to get a feedback on Epic on how they planned to manage this. This may avoid missing stuff like Shammah said…

In order to allow Blueprints to implement functions like ChoosePlayerStart, GetDefaultPawnClassForController, and a great many more I had to make them BlueprintNativeEvents. Unfortunately that meant the C++ implementations of those functions are no longer named ChoosePlayerStart (for example), and instead the virtual you need to override is ChoosePlayerStart_Implementation. Otherwise it will work as before. This will be covered in the upgrade notes for 4.8 once the full release comes out, unfortunately we don’t have a preview version of the upgrade notes at this point.

As for DefaultTimer I chose to get rid of it as for games that don’t make use of it, it was just a wasteful timer ticking away for no reason. And for games that do make use of it, you can trivially redefine it in your own header and ideally give it a more appropriate name.

Apologies for the inconvenience.

ok so it’s an easy upgrade.

Thanks for the update.

For anyone wondering how to fix the DefaultTimer, the ShooterGame simply added the following function:



	virtual void PreInitializeComponents() override;

	/** Handle for efficient management of DefaultTimer timer */
	FTimerHandle TimerHandle_DefaultTimer;




void AShooterGameMode::PreInitializeComponents()
{
	Super::PreInitializeComponents();

	GetWorldTimerManager().SetTimer(TimerHandle_DefaultTimer, this, &AShooterGameMode::DefaultTimer, GetWorldSettings()->GetEffectiveTimeDilation(), true);
}