5.Player Classes

Player Base Class:

All playable classes in the example templates derive from the BP_PlayerBase class inside of the Common folder structure.

This class handles all of the most generic functionality that most endless runner games tend to implement such as managing the state of play to enable/disable player input, player collision, spawning and respawning, effects, Invincibility flash and much more.

On top of this things like the material instance for the current playable class type will be stored. This is done by calling the function StoreMaterialInstance from the EventBeginPlay.

This function will call a global function library to check against the validity of either a Skeletal Mesh, Paper Flipbook, Static Mesh or Paper Sprite.

This will allow you to have one parent class that accounts for any type of component type to visualise your player depending on the type of game you’re making. Be sure here though that you’re not filling multiple component types as this will return an ambiguous Player Material Instance reference which will stop things like the invincibility flash or colour swapping from working correctly.

Child Classes:

The child classes are all responsible for handling their game type specific functionality for the provided templates.

The main thing for each of the child player classes in the examples are the handling of player input. Each class has this dropped into a specific Input graph.

This is intended to help keep the classes tidy whilst also making it easy to find and update the way your player class will respond to player input.

There’s also an example of multiple levels of inheritance in the Lizard Runner template. Here the BP_PlayerBase handles all of the generic functionality. Then the BP_PlayerBaseLizardRunner handles all of the game type specific logic such as movement input, switching colours and the unique lose condition. BP_PlayerBaseLizardRunner is then the parent class of both the BP_PlayerLizardRunner3D and BP_PlayerLizardRunner2D which handle the 2D and 3D specific functionality such as the jump/land visual effects and the player visualisation.

Last updated