quarta-feira, 22 de junho de 2016

BP Compendium 2: Player Controller

Player Controller


The "Controller" class has two main subclasses. The "PlayerController" class is used by human players and the "AIController" class uses artificial intelligence to control the "Pawn". In a simple game it is not necessary to create a Blueprint based on "PlayerController" as Unreal Engine already uses a default instance of "PlayerController" which is sufficient for most cases.

Objects of "Pawn" and "Character" classes only receive Input events if they are being possessed by a "PlayerController". So the use of a "PlayerController" is required even if it is the default. Input events can be placed on the "Player Controller" or on the "Pawn", but events and actions related to the movement of a "Pawn" should be in the class that represents the "Pawn".

For example, if the player controls a character who can use several different types of vehicles such as car, helicopter and speedboat. Each vehicle is represented by a subclass of "Pawn" and must contain the equivalent move actions. But an Input event that pause the game should not be in the "Pawn" class, because it would have to be repeated in all subclasses of "Pawn" used by the game. The ideal place for this type of input event that is not related to "Pawn" is in the "PlayerController" class.

Create a Blueprint based on "PlayerController" class and click the "Class Defaults" button to view the specific attributes of the "PlayerController" class.


You can specify a new "CameraManager" class. If none is specified, a default class is used that controls the active camera used by the Pawn being controlled. Other attributes allow you to adjust the scale used in the inputs related to rotation.

The image below shows a simple way to pause/unpause the game when the "P" key is pressed. These actions are in a "PlayerController". It used the "SetGamePaused" function that receives a Boolean value (true or false) as input. Each call to the FlipFlop macro toggles the value of the variable "Is A" which is used to determine whether the game should pause or unpause. A very important detail, in the input event of the "P" key is necessary to check the "Execute when Paused" option.

Click to enlarge


Table of Contents