UDK Characters, Controller, Pawn
In the UDK, a character is split into two parts:
- A physical representation responsible for interacting with the world and notifying the logical part of interactions and events
- A logical part that issues commands to the physical part and responds to event notifications from the physical part
The physical part of a character is the Pawn class and its descendants. The logical part of a character is the Controller class and its descendants.
Pawn
Pawn is the simpler of the two as it is a basic Actor that has the ability to move around the map in some way, collide with other Actors, and generally interact with the map. What a Pawn lacks is the will to do anything as it is a lot like a vehicle without a driver. Let's look at some of the more important of Pawn's properties.
var editinline repnotify Controller Controller;
The Controller property on a Pawn is a member variable that let's us retrieve the Controller object currently associated with this Pawn. If this Pawn currently has no Controller associated, this will be None.
var class<AIController> ControllerClass; // default class to use when pawn is controlled by AI
The ControllerClass property stores the class of Controller to spawn when SpawnDefaultController is called on this pawn. This property is declared to be restricted to classes inheriting from AIController; as we will see soon, AIController is a class that inherits from Controller and it is the base class of all AI decision making controllers.
UTPawn
While the Pawn class contains the generic functionality that every Pawn would need (like being associated with a Controller), UTPawn contains the functionality required to make the Pawn shoot and run around like an Unreal Tournament character (this is what UT stands for). We will sometimes extend this class when we need our Pawns to retain the functionality of a UT character.
Be warned that if you choose to use UTPawn, you should also make sure to use UTBot, UTPlayerController, and UTGame; otherwise, your code may not execute or may behave unexpectedly.
GetHumanReadableName
UTPawns override this Actor base function to return the name of the pawn as a character.
Controller
Much like how a Pawn is the physical part of a character that interacts with the world, a Controller is the decision making part of the character and is responsible for issuing commands to the pawn. In this way, a player and an AI could both be considered decision makers as a player issues commands through input devices while AI examines its environment to find the next command to issue to the pawn.
Let's look at some of the more important properties in the Controller class.
/** Pawn currently being controlled by this controller. Use Pawn.Possess() to take control of a pawn */
var editinline repnotify Pawn Pawn;
The Pawn property on a Controller is a member variable that let's us retrieve the Pawn object currently associated with this Controller. If this Controller currently has no Pawn associated, this will be None.
PlayerController, AIController
While the base class Controller is the most generic form of Controller in the UDK, it is not the class that you will often want to subclass. Depending on if you need to create a controller that acts based on the state of input devices or if you need to create an autonomous controller requiring no human input, you should either subclass PlayerController or AIController, respectively.
We will learn more about PlayerController and AIController in future notes. For now, it suffices for you to know that PlayerController represents a controller guided by input devices and that AIController represents an autonomous controller.
UTPlayerController, UTBot
Similar to how Pawn is descended by UTPawn which represents a Pawn possessing the traits required to be an Unreal Tournament character, UTPlayerController and UTBot descend from PlayerController and AIController respectively and represent human and bot controllers possessing the required traits to function as the decision making for Unreal Tournament characters.
Future
We will cover more Controller functionality in the future; this is all you need to get started.