Introduction to Unity: Particle Systems
Unity’s particle system is both robust and feature packed. In this tutorial, you’ll learn the ins-and-outs of it to create both fire and explosions. By Anthony Uccello.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Introduction to Unity: Particle Systems
25 mins
- Getting Started with Particle Systems
- Adding a Particle System
- A Closer Look at a Particle System
- More Main Module Properties
- Introducing the Emission Module
- Adding a Custom Texture
- Changing the Particle System’s Shape
- Changing Size Over Lifetime
- Building a Bomb (Effect)
- Building the Explosion
- Changing Color
- Where to Go From Here?
Particle systems are like salt; just a small amount can add extra “pizzazz” to whatever you’re cooking up. Modern games that don’t use particle systems in some manner can feel quite bland.
Back in the old days, you needed the black arts of graphics programming to create even a single wisp of smoke. Thankfully, Unity makes creating particle systems quite simple with a modular, built-in particle system named Shuriken, which is easy to learn but lets you create complex effects.
In this tutorial, you’ll learn the following:
- How to add a new particle system in Unity.
- What the most commonly used particle system modules do and how to use them.
This tutorial has two main parts; in the first part, you’ll build the flames of a torch. In the second part, you’ll create a bomb explosion effect.
Getting Started with Particle Systems
Download the starter project for this tutorial and extract it to a convenient location. Note that you will need to use at least Unity 2017.2 to work with this project.
Open up the Starter Project in Unity. The assets inside are sorted into several folders:
- Materials: Holds the fire material.
- Models: Contains the torch and bomb models and their materials.
- Prefabs: Holds the bomb prefab.
- Scenes: Contains the Torch and Bomb scenes.
- Scripts: Holds the initial scripts.
- Textures: Contains the texture for the fire material.
Now that you’ve seen where everything is stored, you can start to learn how particle systems work in Unity.
Adding a Particle System
A particle system generally emits particles in random positions within a predefined space, which can have a shape like a sphere or a cone. The system determines the lifetime of the particle itself, and when that lifetime expires, the system destroys the particle.
One nice thing about particle systems is that they are components that you can add to any GameObject in the scene. Want to have your sharks emit lasers from their eyes? Simply add a particle system to the shark eye GameObject, and your sharks will be unstoppable!
Open up the Torch scene from your Project Window and run the scene:
There’s not much going on at the moment. The torch hangs on the wall, but there’s no fire to be seen. You’ll need to add a particle system first.
Stop running the scene and select TorchFireParticles inside the Hierarchy. Inside the Inspector, click the Add Component button. Search for Particle System and click to add it:
Play your scene; you’ll see you have particles emitting already:
When you select a GameObject with an attached particle system, you’ll notice a black dialog in the lower right-hand corner of the scene view. This dialog lets you simulate or stop the particle system. Clicking Simulate activates your particle system and changes the button to a Pause button. To stop the simulation, click the “Stop” button.
This dialog is useful for designing particle systems that run on a fixed timeline, such as explosions.
A Closer Look at a Particle System
Take a look at the Inspector. You’ll notice the particle system Component you added has several subsections:
Each of these subsections is called a Module. These Modules contain the settings for the particle system. The Module expanded by default is known as the Main module:
The Main module is the meat and bones of any particle system in Unity. The most common particle settings live here:
For your fire effect, leave this disabled to make it look like the torch was just ignited.
Set the lifetime to 4 seconds; this ensures the flame won’t be too tall.
Set the speed to 0.75; this will make the fire effect slower and more dense.
- Duration: The length of time in seconds for the particle system to run. Leave this at the default value of 5.00.
- Looping: Repeatedly emit particles until the particle system stops. The cycle restarts once the Duration time is reached. The fire needs to burn continuously, so leave this enabled.
-
Prewarm: Only used when Looping is enabled. The Particle System will act as if it’s already completed a full cycle on start-up.
For your fire effect, leave this disabled to make it look like the torch was just ignited.
- Start Delay: The delay in seconds before the particle system starts emitting. Leave this at the default value of 0.
-
Start Lifetime: The initial lifetime in seconds for the particles. The particle is destroyed after this elapsed time.
Set the lifetime to 4 seconds; this ensures the flame won’t be too tall.
-
Start Speed: The initial speed of the particles. The greater the speed of the particles, the more spread out they will be.
Set the speed to 0.75; this will make the fire effect slower and more dense.
Before continuing, run your scene to see the effect of your changes:
You’ve set up the torch, but the fire effect still leaves a lot to be desired. Thankfully, the Main module has additional options to further refine the shape and behavior of your torch.