quarta-feira, 15 de junho de 2016

BP Compendium 2: Object-oriented programming

Object-oriented programming


Since its first version, the Unreal Engine was based on the principles of object-oriented programming. An object contains data that is represented by its variables and also has behaviors that are represented by Actions. Several objects interact to accomplish the goal of a program.

Classes x Objects

A class is the definition of data and behavior that will be used by a particular type of object. A Blueprint represents a class:


An object is an instance of a class. For example, there is only one "Actor" class but a level has several actors. Each of these actors is an instance of the "Actor" class.

Encapsulation:

Encapsulation consists in hide the complexity of a class. For this, each class must be as independent as possible by avoiding interaction with many classes. It should be available to other classes only the data and functions actually needed for the use of this class to facilitate understanding.

As an example, when a function is created in Blueprint, you can specify the level of access to this function. Private means that access can only be done in the Blueprint class that has the function. In Protected the function can be accessed in subclasses. In Public any other class can call the function.


Inheritance

When a new Blueprint is created, you need to define which is the Parent class. All variables and Actions of the Parent class will be part of the child class, which is also known as subclass. This concept is called Inheritance. Inheritance is also used to define the type of an object because the object accumulates all types related to the parent class.

For example, the "Pawn" class is a subclass of "Actor" class. If a Blueprint is created using "Pawn" as parent class, it can be said that this new Blueprint is of the "Pawn" type and is also of the "Actor" type.

In "MyBlueprint" tab you can see the variables that were inherited from the parent class. Click the eye icon and select the "Show Inherited Variables" option.




Table of Contents