For our first Blueprint, let's make use of the Level Blueprint system to create a simple action of a flickering light. Often a staple of horror games, lights that flicker can cause fear in players of not being able to see certain things for a random period of time.
Before we start working within the Unreal Editor, we will need to have a project to work with:
Cookbook_Chapter8
). Once you are finished, click on Create Project.Example Code
folder, drag and drop the NightScene map provided into your project folder and open it:In the middle of the map, you'll notice that there is a light. We're going to make this randomly start to flicker for a time:
This panel consists of a number of parts that will look familiar to those who have worked with UE3's Kismet system. The EventGraph on the right-hand side will contain the events and functions (which I'll sometimes also refer to as actions), which are called inside the game. Think of this in terms of when something happens (the events), we will do something (the functions).
Begin Play
and select the Event Begin Play event. This event occurs whenever the game starts, so as soon as the player is spawned, whatever functions are called from it, will happen.This will create a variable that is a reference to the object in the scene. We can use this variable in the function's parameters.
Intensity
and select the Set Intensity (Light Component) function.You'll notice that the function (note the fancy f icon on the left-hand side) has two properties, the Target and the New Intensity. This will change the PointLight (Target) to whatever the value on New Intensity is.
You'll notice that now the world is pitch black. This is because the value of Set Intensity is now set to 0
. If you have the Level Blueprint window open and then hit the Play button again, you'll actually see the action being executed:
Random
and from the list, select Random Float in Range. Under Max, put in 2000.To move around the Level Blueprint's Event Graph window, right-click and hold, then drag. To zoom in and out, use the mouse wheel. To drag individual elements around left-click and drag them. For more hotkeys and information on moving around Blueprints, refer to https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/CheatSheet/index.html.
Now if you were to play the game, you should notice that the light has a different brightness every time we play it. However, if we want the light to flicker, we should change the intensity value a lot of times as long as the game is running.
This is effectively creating a loop, causing the Set Intensity function to be called after every .2
seconds. If you hit the play button to see the actions executed, you'll notice that the actions are continuously happening, and in the game, you'll see that the values are indeed changing, but we notice that it will always change at a fixed rate which is predictable. A flickering light would be nicer to not be as static in terms of when the value changes so players are unsure as to when it will happen.
0
and 0.2
.Flashing Light
, and press Enter.With that, our flickering light is working correctly and it's looking good!
3.15.176.204