AIController clean up?

Stupid Question:

I assume its our responsibility to clean up AIControllers? I assumed that any actor that is dynamically created should be cleaned up.

I can see how player controllers should hang around so they can posses a new pawn. But AI controllers aren’t really going to do that.

I tried destroying the controller from the pawn on unposses. Mostly as a stab in the dark. But it still lingers in the outliner.

My question is what is the ideal way of managing the AI controllers and ai pawns really? Basically AI dies, what should be the destruction pattern to follow?

Or is there a magic system to clean them up? :slight_smile:

AIControllers without player state (default option, AAIController::bWantsPlayerState) should be automatically destroyed when pawn is removed. Check APawn::DetachFromControllerPendingDestroy() for details.

Since there’s no concept of “death” in engine’s pawn, it’s limited to EndPlay, Destroyed, OutsideWorldBounds and Reset events. If your pawn should cleanup controller when it dies (and usually they do need it), it’s best to add DetachFromControllerPendingDestroy() call in your death handler.