APawn::SpawnDefaultController
#include "GameFramework/Pawn.h"
Access: public
Specifiers: virtualUFUNCTIONBlueprintCallable
Description
Spawns the default controller class for this Pawn (from AIControllerClass) and immediately possesses the pawn with it. Call this after manually spawning a pawn that should be AI-controlled.
Caveats & Gotchas
- • Only runs on the server (or in standalone). Calling it on a client is a no-op — the AI controller is not replicated and possession is server-authoritative.
- • If AutoPossessAI is set to anything other than Disabled, the engine calls this automatically on BeginPlay. Calling it again will spawn a second controller and may leave the first dangling.
- • The spawned controller class is read from AIControllerClass. If that is null or not set in the pawn's defaults, no controller is spawned and no error is logged — it silently does nothing.
Signature
ENGINE_API virtual void SpawnDefaultController(); Return Type
void Example
Manually spawn an AI-controlled pawn at runtime C++
AMyAIPawn* NewPawn = GetWorld()->SpawnActor<AMyAIPawn>(SpawnLocation, SpawnRotation);
if (NewPawn && HasAuthority())
{
// AutoPossessAI is Disabled on this pawn, so we must call manually
NewPawn->SpawnDefaultController();
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?