AController

Controllers are non-physical actors that can possess a Pawn to control its actions.

Windows
MacOS
Linux

Inheritance Hierarchy

Syntax

class AController :
    public AActor,
    public INavAgentInterface

Remarks

Controllers are non-physical actors that can possess a Pawn to control its actions. PlayerControllers are used by human players to control pawns, while AIControllers implement the artificial intelligence for the pawns they control. Controllers take control of a pawn using their Possess() method, and relinquish control of the pawn by calling UnPossess().

Controllers receive notifications for many of the events occurring for the Pawn they are controlling. This gives the controller the opportunity to implement the behavior in response to this event, intercepting the event and superseding the Pawn's default behavior.

ControlRotation (accessed via GetControlRotation()), determines the viewing/aiming direction of the controlled Pawn and is affected by input such as from a mouse or gamepad.

Variables

Name Description

Protected variable

uint8: 1

 

bAttachToPawn

If true, the controller location will match the possessed Pawn's location.

Protected variable

uint8: 1

 

bCanPossessWithoutAuthority

Whether the controller must have authority to be able to call possess on a Pawn

Protected variable

uint8: 1

 

bIsPlayerController

Whether this controller is a PlayerController.

Protected variable

FRotator

 

ControlRotation

The control rotation of the Controller. See GetControlRotation.

Protected variable

uint8

 

IgnoreLookInput

Ignores look input.

Protected variable

uint8

 

IgnoreMoveInput

Ignores movement input.

Public variable

FInstigatedAnyD...

 

OnInstigatedAnyDamage

Called when the controller has instigated damage in any way

Protected variable

FPawnChangedSig...

 

OnNewPawn

Public variable

APlayerState &#...

 

PlayerState

PlayerState containing replicated information about the player using this controller (only exists for players, not NPCs).

Public variable

TWeakObjectPtr<...

 

StartSpot

Actor marking where this controller spawned in.

Public variable

FName

 

StateName

Current gameplay state this controller is in

Constructors

Name Description

Public function

AController

(
    const FObjectInitializer& ObjectIn...
)

Default Constructor

Functions

Name Description

Protected function Virtual

void

 

AddPawnTickDependency

(
    APawn* NewPawn
)

Add dependency that makes us tick before the given Pawn.

Protected function Virtual

void

 

AttachToPawn

(
    APawn* InPawn
)

Physically attach the Controller to the specified Pawn, so that our position reflects theirs.

Protected function Virtual

void

 

BeginInactiveState()

State entered when inactive (no possessed pawn, not spectating, etc).

Public function Virtual

void

 

ChangeState

(
    FName NewState
)

Change the current state to named state

Public function Virtual

void

 

CleanupPlayerState()

Called from Destroyed().

Public function

void

 

ClientSetLocation

(
    FVector NewLocation,
    FRotator NewRotation
)

Replicated function to set the pawn location and rotation, allowing server to force (ex. teleports).

Public function

void

 

ClientSetRotation

(
    FRotator NewRotation,
    bool bResetCamera
)

Replicated function to set the pawn rotation, allowing the server to force.

Public function Virtual

void

 

CurrentLevelUnloaded()

Called when the level this controller is in is unloaded via streaming.

Protected function Virtual

void

 

DetachFromPawn()

Detach the RootComponent from its parent, but only if bAttachToPawn is true and it was attached to a Pawn.

Public function Virtual

void

 

DisplayDebug

(
    UCanvas* Canvas,
    const FDebugDisplayInfo& DebugDisp...,
    float& YL,
    float& YPos
)

Protected function Virtual

void

 

EndInactiveState()

Called when leaving the inactive state

Public function Virtual

void

 

FailedToSpawnPawn()

GameMode failed to spawn pawn for me.

Public function Virtual

void

 

GameHasEnded

(
    AActor* EndGameFocus,
    bool bIsWinner
)

Called from game mode upon end of the game, used to transition to proper state.

Public function Const

ACharacter &...

 

GetCharacter()

Getter for Character

Public function Virtual Const

FRotator

 

GetControlRotation()

Get the control rotation.

Public function Virtual Const

FRotator

 

GetDesiredRotation()

Get the desired pawn target rotation

Public function

FPawnChanged...

 

GetOnNewPawnNotifier()

Public function Const

APawn *

 

GetPawn()

Getter for Pawn

Public function Const

T *

 

GetPlayerState()

Public function Virtual Const

void

 

GetPlayerViewPoint

(
    FVector& Location,
    FRotator& Rotation
)

Returns Player's Point of View For the AI this means the Pawn's 'Eyes' ViewPoint For a Human player, this means the Camera's ViewPoint

Public function Const

FName

 

GetStateName()

Protected function Const

USceneCompon...

 

GetTransformComponent()

Returns TransformComponent subobject

Public function Virtual Const

AActor *

 

GetViewTarget()

Get the actor the controller is looking at

Public function Virtual

void

 

InitPlayerState()

Spawns and initializes the PlayerState for this Controller

Public function Virtual

void

 

InstigatedAnyDamage

(
    float Damage,
    const UDamageType* DamageType,
    AActor* DamagedActor,
    AActor* DamageCauser
)

Called when this controller instigates ANY damage

Public function Const

bool

 

IsInState

(
    FName InStateName
)

States (uses FNames for replication, correlated to state flags)

Public function Virtual Const

bool

 

IsLocalController()

Returns whether this Controller is a local controller.

Public function Const

bool

 

IsLocalPlayerController()

Returns whether this Controller is a locally controlled PlayerController.

Public function Virtual Const

bool

 

IsLookInputIgnored()

Returns true if look input is ignored.

Public function Virtual Const

bool

 

IsMoveInputIgnored()

Returns true if movement input is ignored.

Public function Const

bool

 

IsPlayerController()

Returns whether this Controller is a PlayerController.

Public function Const

APawn *

 

K2_GetPawn()

Return the Pawn that is currently 'controlled' by this PlayerController

Public function Virtual Const

bool

 

LineOfSightTo

(
    const AActor* Other,
    FVector ViewPoint,
    bool bAlternateChecks
)

Checks line to center and top of other actor

Protected function Virtual

void

 

OnPossess

(
    APawn* InPawn
)

Overridable native function for when this controller possesses a pawn.

Public function Virtual

void

 

OnRep_Pawn()

Replication Notification Callbacks

Public function Virtual

void

 

OnRep_PlayerState()

Protected function Virtual

void

 

OnUnPossess()

Overridable native function for when this controller unpossesses its pawn.

Public function Virtual

void

 

PawnPendingDestroy

(
    APawn* inPawn
)

Called to unpossess our pawn because it is going to be destroyed.

Public function Virtual

void

 

Possess

(
    APawn* InPawn
)

Handles attaching this controller to the specified pawn.

Protected function

void

 

ReceiveInstigatedAnyDamage

(
    float Damage,
    const UDamageType* DamageType,
    AActor* DamagedActor,
    AActor* DamageCauser
)

Event when this controller instigates ANY damage

Protected function

void

 

ReceivePossess

(
    APawn* PossessedPawn
)

Blueprint implementable event to react to the controller possessing a pawn

Protected function

void

 

ReceiveUnPossess

(
    APawn* UnpossessedPawn
)

Blueprint implementable event to react to the controller unpossessing a pawn

Protected function Virtual

void

 

RemovePawnTickDependency

(
    APawn* InOldPawn
)

Remove dependency that makes us tick before the given Pawn.

Public function Virtual

void

 

ResetIgnoreInputFlags()

Reset move and look input ignore flags.

Public function Virtual

void

 

ResetIgnoreLookInput()

Stops ignoring look input by resetting the ignore look input state.

Public function Virtual

void

 

ResetIgnoreMoveInput()

Stops ignoring move input by resetting the ignore move input state.

Public function Virtual

void

 

SetControlRotation

(
    const FRotator& NewRotation
)

Set the control rotation.

Public function Virtual

void

 

SetIgnoreLookInput

(
    bool bNewLookInput
)

Locks or unlocks look input, consecutive calls stack up and require the same amount of calls to undo, or can all be undone using ResetIgnoreLookInput.

Public function Virtual

void

 

SetIgnoreMoveInput

(
    bool bNewMoveInput
)

Locks or unlocks movement input, consecutive calls stack up and require the same amount of calls to undo, or can all be undone using ResetIgnoreMoveInput.

Public function Virtual

void

 

SetInitialLocationAndRotation

(
    const FVector& NewLocation,
    const FRotator& NewRotation
)

Set the initial location and rotation of the controller, as well as the control rotation.

Public function Virtual

void

 

SetPawn

(
    APawn* InPawn
)

Setter for Pawn. Normally should only be used internally when possessing/unpossessing a Pawn.

Public function

void

 

SetPawnFromRep

(
    APawn* InPawn
)

Calls SetPawn and RepNotify locally

Public function Virtual

void

 

StopMovement()

Aborts the move the controller is currently performing

Public function Virtual

void

 

UnPossess()

Called to unpossess our pawn for any reason that is not the pawn being destroyed (destruction handled by PawnDestroyed()).

Overridden from AActor

Name Description

Public function Virtual

void

 

Destroyed()

Called when this actor is explicitly being destroyed during gameplay or in the editor, not called during level streaming or gameplay ending

Public function Virtual Const

void

 

GetActorEyesViewPoint

(
    FVector& OutLocation,
    FRotator& OutRotation
)

Returns the point of view of the actor.

Public function Virtual Const

FString

 

GetHumanReadableName()

Returns the human readable string representation of an object.

Public function Virtual

void

 

K2_DestroyActor()

Destroy the actor

Public function Virtual

void

 

PostInitializeComponents()

Overridden to create the player replication info and perform other mundane initialization tasks.

Public function Virtual

void

 

Reset()

Reset actor to initial state - used when restarting level without reloading.

Public function Virtual

void

 

TickActor

(
    float DeltaTime,
    enum ELevelTick TickType,
    FActorTickFunction& ThisTickFuncti...
)

Dispatches the once-per frame Tick() function for this actor

Overridden from UObject

Name Description

Public function Virtual Const

void

 

GetLifetimeReplicatedProps

(
    TArray< FLifetimeProperty >& OutLi...
)

Returns the properties used for network replication, this needs to be overridden by all actor classes with native replicated properties

Overridden from INavAgentInterface

Name Description

Public function Virtual Const

void

 

GetMoveGoalReachTest

(
    const AActor* MovingActor,
    const FVector& MoveOffset,
    FVector& GoalOffset,
    float& GoalRadius,
    float& GoalHalfHeight
)

Get cylinder for testing if actor has been reached

Public function Virtual Const

FVector

 

GetNavAgentLocation()

Retrieves Agent's location

Public function Virtual Const

const FNavAg...

 

GetNavAgentPropertiesRef()

Retrieves FNavAgentProperties expressing navigation props and caps of represented agent the function will be renamed to GetNavAgentProperties in 4.8.

Public function Virtual Const

IPathFollowi...

 

GetPathFollowingAgent()

Retrieves PathFollowingAgent for this NavAgent

Public function Virtual Const

bool

 

IsFollowingAPath()

Checks if the agent is actively following a navigation path

Public function Virtual Const

bool

 

ShouldPostponePathUpdates()

Allows delaying repath requests

Deprecated Functions

Name Description

Public function

APlayerContr...

 

CastToPlayerController()

CastToPlayerController has been replaced by the standard Cast To node.

Public function Virtual

void

 

InitNavigationControl

(
    UObject*& PathFollowingComp
)

InitNavigationControl is depracated. The function lost its meaning due to better Engine-AIModule code separation

Public function Virtual

void

 

UpdateNavigationComponents()

UpdateNavigationComponents is depracated. The function lost its meaning due to better Engine-AIModule code separation.

See Also

References

Module

Engine

Header

Runtime/Engine/Classes/GameFramework/Controller.h

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback