RealDocs

AGameModeBase::SpawnDefaultPawnAtTransform

function Engine Blueprint Since 4.14
#include "GameFramework/GameModeBase.h"
Access: public Specifiers: virtualUFUNCTIONBlueprintNativeEvent

Description

Spawns an instance of the default pawn class at the given transform and returns it. Called by RestartPlayerAtTransform() and RestartPlayerAtPlayerStart() to actually instantiate the pawn actor.

Caveats & Gotchas

  • BlueprintNativeEvent — override in C++ by implementing SpawnDefaultPawnAtTransform_Implementation(), not the base function. Calling Super:: from a C++ _Implementation correctly invokes the default logic.
  • Returns null if DefaultPawnClass is unset or the spawn fails due to a collision blocking it. The RestartPlayer* functions do not guard against null before possessing the result, so a null return will log an error and leave the controller without a pawn.

Signature

UFUNCTION(BlueprintNativeEvent, Category=Game)
ENGINE_API APawn* SpawnDefaultPawnAtTransform(AController* NewPlayer, const FTransform& SpawnTransform);

Parameters

Name Type Description Default
NewPlayer AController* The controller for whom the pawn is being spawned.
SpawnTransform const FTransform& The world transform at which to spawn the pawn.

Return Type

APawn*

Example

Spawn a different pawn class based on runtime game state C++
APawn* AMyGameMode::SpawnDefaultPawnAtTransform_Implementation(AController* NewPlayer, const FTransform& SpawnTransform)
{
	TSubclassOf<APawn> PawnClass = bEliteMode ? ElitePawnClass : DefaultPawnClass;
	FActorSpawnParameters SpawnParams;
	SpawnParams.Owner = NewPlayer;
	SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
	return GetWorld()->SpawnActor<APawn>(PawnClass, SpawnTransform, SpawnParams);
}

Version History

Introduced in: 4.14

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.