Create a candle flame in UE4
A simple solution without sprite sheets
Recently, I created a candle flame in the Unreal Engine 4. I did not find the method I used anywhere else, so I decided to write a little tutorial and share it with the world.
The final result
Before we start, here is a preview of the result:
The flickering is created via UV distortions in the material. For the coloring, scaling, etc. I use the Niagara particle system.
Let’s start
First of all, you need 2 Grayscale textures:
- Candle flame mask
- Noise
The candle flame mask should be a grayscale texture with the shape of a candle flame. The edges should be a bit smoother and the lower end should have a gradient to transparent.
The noise is a simple Perlin noise. We’ll need it to deform our flame shape. Here are the textures I created. Feel free to use them:
The Material
The candle flickering happens in the material using UV distortions. Using this technique right, the effect can be very realistic and modifiable. There is no need for a Sprite texture which saves performance and time and also gives us access to modify the flame in realtime.
Basic Material settings
Things that need to be changed:
Blend Mode:
Set the blend mode to additive.
Why:
The additive blend adds the pixels of the material to the pixels of the background.
This is useful for fire effects since there is no darkening of the base color.
Shading Model
Set the shading model to unlit.
Why:
The unlit shading model only outputs emissive. This is perfectly suited for fire. We don't need other outputs like base color, roughness, etc.
Implement the candle flickering
To create the flickering of the candle, we need to distort the UV’s of the flame texture:
In the first step (red), we use a Panner node to create a “movement” of the noise texture. Notice how there are two different noise tilings. One is stretched, and the other is not.
The stretched one gives the flame a more basic movement, while the other adds more details to the flame itself.
In the second step (yellow), we append the two noises together and define an overall strength for the noise.
After this, the texture coordinate of the flame is added to the distortion.
To correct the location of the flame in the UV space, a constant of 0.3 is added to the distortion.
Remaining material
The rest of the material is just putting together, and adding a Particle Color node which is needed for the next step:
The Particle System
The last step is creating the particle system using Niagara.
Steps:
- Create a new Niagara System named “Candle”
- Add a new Emitter from type Fountain
- Delete the following Modules from the emitter:
Calculate Size by Mass, Sphere Location, Gravity Force, Drag, Scale Color - Add a Color module and a Set Variables module for the SpriteSize under the Particle Update section
It should look like this:
5. In the Sprite Renderer section, select the candle flame material. Also, change the Facing Mode to Face Camera Position. This will lead to a more realistic look as the flame will not rotate directly to the player, if you watch it from the top.
6. Set the spawn rate to something more than 30. Too low values will result in flickering.
7. Depending on how stretched your flame should look, set the Lifetime around 0,3.
8. Use a ranged vector to define the velocity. Adding a speed difference between single flames will improve the look.
9. Add a color curve.
10. Use a curve to scale the flames down over time. With the ScaleCurve parameter, you can change the width and the height of the flames.
11. Place the Niagra system in the world.
That’s all, Enjoy your beautiful candle!
If you want to know how to create smoke trails fitting to the candle, check out this tutorial.
If you have any questions, please let me know!
Do you want to learn more about game development?
Check out https://gameinspired.substack.com/ and bring yourself to the next level!