Creating a Problem Solving System in UE4 (1/2)

Ali Siddiqui
code3100
Published in
3 min readApr 2, 2017

One of the ideas that we talked to Barry about was the player needed to find a light source. They would find (or be given) a torch and would then have to find the battery for the torch to be have better vision of the surrounding area.

My Goal: Create a torch that could be picked up, however it would only work if the player found the battery.

Step 1

Firstly, I modeled a simple flashlight in 3DS Max, UVW Unwrapped it and imported into UE4 and checking the ‘Import Skeletal Mesh’ option. This allows me to pick up the object and interact with it as if it is has physics characteristics. Then I converted it into a Blueprint Actor so I could use it in other scripts as a variable.

Imported Assets of Torch

Step 2

I have also added a Blueprint interface that allows me to communicate between the Flashlight and FirstPersonCharacter scripts. Events such as ‘pressing this key will turn the light on,’ ‘destroy the actor when the player picks it up.’

Blueprint Interface Functions
Key input going into the interface functions

Step 3

Now I have to add the logic to the character blueprint where the torch is added to the character once the player picks it up.

Placement of torch and light source on the character model
FirstPersonCharacter Blueprint Script

This part of the script checks to see if the player has a flashlight, if not, add it to the player. It also toggles the visibility of the flashlight based on whether the key input is true or false AND if the player has the battery or not.

Step 4

adding battery as a blueprint actor and using boolean to turn on the light switch

For this prototype, I used a simple cube mesh to represent the battery.

Battery Mesh
Script used in battery blueprint

The main logic of this script is:

  • Press input key > is player within collision box? if yes > check if the player has already picked up a flashlight > Print ‘Flashlight Needed’ if false > Destroy actor
  • Press input key > is player within collision box? if no > don’t add to inventory

In-Game

Two assets used in the prototype
‘Need Battery’ printed when player tries to use flashlight
Battery Mesh
‘Flashlight Power On’ when battery picked up
Flashlight works after picking up battery

This is definitely an extremely simplified version of the scripts, however it outlines the basic logic of how this game mechanic works and also shows the importance of booleans and communication between blueprint scripts. This was also very useful as the same logic can easily be applied when scripting for our final game.

--

--