Saturday, 8 December 2018

Game - Health pick-up item

In my Unreal game, I added a prefab pick-up object which allowed the player to gain health if they took damage throughout the level.

How the code works:
The pickup object had a specific blueprint class which added health, and would run if the player hit the item.

If an actor collided with the health item, which was run with the Event ActorBeginOverlap, it would first compare if the other actor was the player character. If this is true, the code would access the player class (Cast To FirstPersonCharacter...), and add an integer of 10 onto the player's health. Then, the health item would be destroyed, and a sound effect to indicate the pickup would play once.

Blueprint Code:


Final health item:


What I have learnt:

From this mechanic, I have been able to understand the process of accessing variables between different Blueprint classes. In the code, I accessed and set the health variable of the player class, from the Health Item class.