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.
- 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.
- Start Speed: The initial speed of the particles. The greater the speed of the particles, the more spread out they will be.
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.
More Main Module Properties
Select the TorchFireParticles GameObject in the Hierarchy and scroll down to the particle system. Under the Main Module, take a look at the following properties:
Set the size to 3; this is a manageable size that lets you see the individual particles more clearly.
Keep the rotation at 0°; the particles are round so you will hardly notice the difference.
The image above is from a system with the gravity modifier set to 1, which makes the particles flow down like a waterfall. Leave the gravity in your system at 0; the particles will move upwards with the velocity you set in Start Speed.
Leave your simulation set to Local Space. The effect will only be visible once the particle system is moved.
- Start Size: the initial size of the particles.
- Start Rotation: The initial rotation angle of the particles.
- Start Color: The initial color of the particles. Keep the color at the default value of pure white (255,255,255); you’ll color the fire via a texture.
- Gravity Modifier: Scales the gravity value set in Unity’s Physics Manager window. If it’s set to 0, the gravity will be turned off.
- Simulation Space: Moves particles in Local Space along with the particle system. While in World Space, particles move freely once emitted.
- Play On Awake: Starts emitting immediately when enabled. If this is turned off, you have to manually start the particle system via script or an animation system. Leave this setting on, as you want the fire to start when the scene starts playing.
- Max Particles: The maximum number of particles the system may have alive at once. If you try to emit more particles than this, they won’t be emitted at all. This setting is primarily for performance reasons, and the default value of 1000 particles is more than enough in this case.
Whew, that was quite a list! But as a result, you’ve learned how to add a particle system to your scene and how to customize it to your liking.
Run your scene again to see the effect of your changes:
It looks a bit more like fire every time, doesn’t it?
It needs more particles though. To do that, you need to change the emission of the system.