Hey there,
I am working in UE5 and following a tutorial to spawn different pawns for players in multiplayer
The suggestion is to override the GetDefaultPawnClassForController_Implementation
function belonging to the GameModeBase
. However I noticed that the function is not virtual in the source code:
/** Returns default pawn class for given controller */
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category=Classes)
UClass* GetDefaultPawnClassForController(AController* InController);
I tried to override anyway but my override does not get called. After placing breakpoints the debugger stops inside the original implementation but not in my override.
My code looks like this
ATP_MLFGameModeBase.h
UCLASS()
class TP_MLF_API ATP_MLFGameModeBase : public AGameMode
{
GENERATED_UCLASS_BODY()
public:
UClass* GetDefaultPawnClassForController_Implementation(AController* InController) override;
private:
};
ATP_MLFGameModeBase.cpp
ATP_MLFGameModeBase::ATP_MLFGameModeBase(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
/* Use our custom Player-Controller Class */
PlayerControllerClass = AMyPlayerController::StaticClass();
}
UClass* ATP_MLFGameModeBase::GetDefaultPawnClassForController_Implementation(AController* InController)
{
/* Override Functionality to get Pawn from PlayerController */
AMyPlayerController* MyController = Cast<AMyPlayerController>(InController);
if (MyController)
{
UE_LOG(LogTemp, Log, TEXT("inside returning MyController"));
return MyController->GetPlayerPawnClass();
}
/* If we don't get the right Controller, use the Default Pawn */
return DefaultPawnClass;
}
I am wondering whether GetDefaultPawnClassForController
can still be overridden or whether this has changed and I should explore other avenues for setting the pawn?