Navigation
API > API/Runtime > API/Runtime/Engine
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.
| Name | AController |
| Type | class |
| Header File | /Engine/Source/Runtime/Engine/Classes/GameFramework/Controller.h |
| Include Path | #include "GameFramework/Controller.h" |
Syntax
UCLASS (Abstract, NotPlaceable, NotBlueprintable,
HideCategories=(Collision, Rendering, Transformation), MinimalAPI)
class AController :
public AActor ,
public INavAgentInterface
Inheritance Hierarchy
- UObjectBase → UObjectBaseUtility → UObject → AActor → AController
Implements Interfaces
Derived Classes
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
AController
(
const FObjectInitializer& ObjectInitializer |
Default Constructor | GameFramework/Controller.h |
Variables
Public
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| OnInstigatedAnyDamage | FInstigatedAnyDamageSignature | Called when the controller has instigated damage in any way | GameFramework/Controller.h |
|
| OnPossessedPawnChanged | FOnPossessedPawnChanged | Called on both authorities and clients when the possessed pawn changes (either OldPawn or NewPawn might be nullptr) | GameFramework/Controller.h |
|
| PlayerState | TObjectPtr< APlayerState > | PlayerState containing replicated information about the player using this controller (only exists for players, not NPCs). | GameFramework/Controller.h |
|
| StartSpot | TWeakObjectPtr< class AActor > | Actor marking where this controller spawned in. | GameFramework/Controller.h | |
| StateName | FName | Current gameplay state this controller is in | GameFramework/Controller.h |
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Character | TObjectPtr< ACharacter > | Character currently being controlled by this controller. | GameFramework/Controller.h | |
| OldPawn | TWeakObjectPtr< APawn > | Used to track when pawn changes during OnRep_Pawn. | GameFramework/Controller.h | |
| Pawn | TObjectPtr< APawn > | Pawn currently being controlled by this controller. Use Pawn.Possess() to take control of a pawn | GameFramework/Controller.h |
|
| TransformComponent | TObjectPtr< USceneComponent > | Component to give controllers a transform and enable attachment if desired. | GameFramework/Controller.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void ChangeState
(
FName NewState |
Change the current state to named state | GameFramework/Controller.h | |
virtual void CleanupPlayerState() |
Called from Destroyed(). Cleans up PlayerState. | GameFramework/Controller.h | |
void ClientSetLocation
(
FVector NewLocation, |
Replicated function to set the pawn location and rotation, allowing server to force (ex. teleports). | GameFramework/Controller.h |
|
void ClientSetRotation
(
FRotator NewRotation, |
Replicated function to set the pawn rotation, allowing the server to force. | GameFramework/Controller.h |
|
virtual void CurrentLevelUnloaded() |
Called when the level this controller is in is unloaded via streaming. | GameFramework/Controller.h | |
virtual void DisplayDebug
(
UCanvas* Canvas, |
GameFramework/Controller.h | ||
virtual void FailedToSpawnPawn() |
GameMode failed to spawn pawn for me. | GameFramework/Controller.h | |
virtual void GameHasEnded
(
AActor* EndGameFocus, |
Called from game mode upon end of the game, used to transition to proper state. | GameFramework/Controller.h | |
ACharacter * GetCharacter() |
Getter for Character | GameFramework/Controller.h | |
virtual FRotator GetControlRotation () |
Get the control rotation. | GameFramework/Controller.h |
|
virtual FRotator GetDesiredRotation() |
Get the desired pawn target rotation | GameFramework/Controller.h |
|
FPawnChangedSignature & GetOnNewPawnNotifier() |
GameFramework/Controller.h | ||
TObjectPtr< APawn > GetPawn () |
Getter for Pawn | GameFramework/Controller.h | |
T * GetPawn () |
Templated version of GetPawn, will return nullptr if cast fails | GameFramework/Controller.h | |
T * GetPlayerState() |
GameFramework/Controller.h | ||
virtual void GetPlayerViewPoint
(
FVector& Location, |
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 | GameFramework/Controller.h |
|
FName GetStateName() |
GameFramework/Controller.h | ||
virtual AActor * GetViewTarget() |
Get the actor the controller is looking at | GameFramework/Controller.h |
|
virtual void InitPlayerState() |
Spawns and initializes the PlayerState for this Controller | GameFramework/Controller.h | |
virtual void InstigatedAnyDamage
(
float Damage, |
Called when this controller instigates ANY damage | GameFramework/Controller.h | |
bool IsInState
(
FName InStateName |
States (uses FNames for replication, correlated to state flags) | GameFramework/Controller.h | |
virtual bool IsLocalController() |
Returns whether this Controller is a local controller. | GameFramework/Controller.h |
|
bool IsLocalPlayerController() |
Returns whether this Controller is a locally controlled PlayerController. | GameFramework/Controller.h |
|
virtual bool IsLookInputIgnored() |
Returns true if look input is ignored. | GameFramework/Controller.h |
|
virtual bool IsMoveInputIgnored() |
Returns true if movement input is ignored. | GameFramework/Controller.h |
|
bool IsPlayerController() |
Returns whether this Controller is a PlayerController. | GameFramework/Controller.h |
|
APawn * K2_GetPawn() |
Return the Pawn that is currently 'controlled' by this PlayerController | GameFramework/Controller.h |
|
virtual bool LineOfSightTo
(
const AActor* Other, |
Checks line to center and top of other actor | GameFramework/Controller.h |
|
virtual void OnRep_Pawn() |
Replication Notification Callbacks | GameFramework/Controller.h | |
virtual void OnRep_PlayerState() |
GameFramework/Controller.h | ||
virtual void PawnPendingDestroy
(
APawn* inPawn |
Called to unpossess our pawn because it is going to be destroyed. | GameFramework/Controller.h | |
| Handles attaching this controller to the specified pawn. | GameFramework/Controller.h |
|
|
virtual void ResetIgnoreInputFlags() |
Reset move and look input ignore flags. | GameFramework/Controller.h |
|
virtual void ResetIgnoreLookInput() |
Stops ignoring look input by resetting the ignore look input state. | GameFramework/Controller.h |
|
virtual void ResetIgnoreMoveInput() |
Stops ignoring move input by resetting the ignore move input state. | GameFramework/Controller.h |
|
virtual void SetControlRotation
(
const FRotator& NewRotation |
Set the control rotation. | GameFramework/Controller.h |
|
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. | GameFramework/Controller.h |
|
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. | GameFramework/Controller.h |
|
virtual void SetInitialLocationAndRotation
(
const FVector& NewLocation, |
Set the initial location and rotation of the controller, as well as the control rotation. | GameFramework/Controller.h |
|
virtual void SetPawn
(
APawn* InPawn |
Setter for Pawn. Normally should only be used internally when possessing/unpossessing a Pawn. | GameFramework/Controller.h | |
void SetPawnFromRep
(
APawn* InPawn |
Calls SetPawn and RepNotify locally | GameFramework/Controller.h | |
void SetPlayerState
(
APlayerState* InPlayerState |
GameFramework/Controller.h | ||
virtual bool ShouldParticipateInSeamlessTravel() |
Returns whether this controller should persist through seamless travel | GameFramework/Controller.h | |
virtual void StopMovement() |
Aborts the move the controller is currently performing | GameFramework/Controller.h |
|
virtual void UnPossess() |
Called to unpossess our pawn for any reason that is not the pawn being destroyed (destruction handled by PawnDestroyed()). | GameFramework/Controller.h |
|
Overridden from AActor
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
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 | GameFramework/Controller.h | |
virtual void GetActorEyesViewPoint
(
FVector& OutLocation, |
Returns the point of view of the actor. | GameFramework/Controller.h | |
virtual FString GetHumanReadableName() |
Returns the human readable string representation of an object. | GameFramework/Controller.h | |
virtual void K2_DestroyActor() |
Destroy the actor | GameFramework/Controller.h | |
virtual void PostInitializeComponents() |
Overridden to create the player replication info and perform other mundane initialization tasks. | GameFramework/Controller.h | |
virtual void Reset() |
Reset actor to initial state - used when restarting level without reloading. | GameFramework/Controller.h | |
virtual void TickActor
(
float DeltaTime, |
Dispatches the once-per frame Tick() function for this actor | GameFramework/Controller.h |
Overridden from UObject
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void GetLifetimeReplicatedProps
(
TArray< FLifetimeProperty >& OutLifetimeProps |
Returns the properties used for network replication, this needs to be overridden by all actor classes with native replicated properties | GameFramework/Controller.h |
Overridden from INavAgentInterface
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void GetMoveGoalReachTest
(
const AActor* MovingActor, |
Get cylinder for testing if actor has been reached | GameFramework/Controller.h | |
virtual FVector GetNavAgentLocation() |
Retrieves Agent's location | GameFramework/Controller.h | |
virtual const FNavAgentProperties & GetNavAgentPropertiesRef () |
Retrieves FNavAgentProperties expressing navigation props and caps of represented agent @NOTE the function will be renamed to GetNavAgentProperties in 4.8. | GameFramework/Controller.h | |
virtual IPathFollowingAgentInterface * GetPathFollowingAgent() |
Retrieves PathFollowingAgent for this NavAgent | GameFramework/Controller.h | |
virtual bool IsFollowingAPath() |
Checks if the agent is actively following a navigation path | GameFramework/Controller.h | |
virtual bool ShouldPostponePathUpdates() |
Allows delaying repath requests | GameFramework/Controller.h |
Protected
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void AddPawnTickDependency
(
APawn* NewPawn |
Add dependency that makes us tick before the given Pawn. | GameFramework/Controller.h | |
virtual void AttachToPawn
(
APawn* InPawn |
Physically attach the Controller to the specified Pawn, so that our position reflects theirs. | GameFramework/Controller.h | |
virtual void BeginInactiveState() |
State entered when inactive (no possessed pawn, not spectating, etc). | GameFramework/Controller.h | |
virtual void DetachFromPawn() |
Detach the RootComponent from its parent, but only if bAttachToPawn is true and it was attached to a Pawn. | GameFramework/Controller.h | |
virtual void EndInactiveState() |
Called when leaving the inactive state | GameFramework/Controller.h | |
USceneComponent * GetTransformComponent() |
Returns TransformComponent subobject | GameFramework/Controller.h | |
bool IsValidControlRotation
(
FRotator CheckRotation |
Return false if rotation contains NaN or extremely large values (usually resulting from uninitialized values). | GameFramework/Controller.h | |
virtual void OnPossess
(
APawn* InPawn |
Overridable native function for when this controller is asked to possess a pawn. | GameFramework/Controller.h | |
virtual void OnUnPossess() |
Overridable native function for when this controller unpossesses its pawn. | GameFramework/Controller.h | |
void ReceiveInstigatedAnyDamage
(
float Damage, |
Event when this controller instigates ANY damage | GameFramework/Controller.h |
|
void ReceivePossess
(
APawn* PossessedPawn |
Blueprint implementable event to react to the controller possessing a pawn | GameFramework/Controller.h |
|
void ReceiveUnPossess
(
APawn* UnpossessedPawn |
Blueprint implementable event to react to the controller unpossessing a pawn | GameFramework/Controller.h |
|
virtual void RemovePawnTickDependency
(
APawn* InOldPawn |
Remove dependency that makes us tick before the given Pawn. | GameFramework/Controller.h |