patreon

 

 

About this project

Skill level 1
Time to complete 10 minutes

New concepts

  1. Introduction to Unity particle effects
  2. Using sorting layers
  3. Editing particle effects
  4. Combining particle effects

Recommended preparation tutorials

Assumed previous experience

As you can see above the prerequisite knowledge for completing this project is virtually nothing. That is because Unity makes particle effects easy, very easy. It is true that there are still advanced techniques to learn if you want to have the most spectacular particle effects possible but we will see that getting started is a breeze. Although this project is suitable for someone with no experience at all it is also the penultimate preparation project before the Unity 2D platformer project.

Create a new project in Unity, call it Particle Systems, and select the 2D option.

Clarifying the terms around particle systems

A particle system emits multiple particles. In addition, particle systems can be combined to create particle effects. We will be using the Unity default particle but each individual particle can have a texture, an animated texture, or even a 3D mesh. Let’s make that fireplace.

Importing and layering the fireplace sprites

Download this next image and then import it into Unity by right-clicking in the Project tab and selecting Import New Asset... Browse the image and import it.

fireplace-back

Position the top/back of the fireplace in the center of the Scene tab by dragging it from the Project tab.

Next, import the next image in the same way we did the previous one. Also, drag it into the Scene tab and line it up so it makes a complete fireplace image with the other half.

fireplace-front

The top/back of the fireplace will be drawn behind our particle effect and the front/bottom will be drawn in front of it. To achieve this we need to create a new Sorting layer and add the front/bottom of the fireplace to it.

Creating a new sorting layer

Make sure the bottom of the fireplace is selected in the Scene tab. In the Inspector tab, find the Sorting layer property on the Sprite Renderer component. Click the drop-down box and select Add Sorting Layer…. Click the + button to add a new layer and type front as the name for the new sorting layer. Any objects assigned to the front layer will be drawn after/on top of anything that is in the default layer. Here is what your Inspector tab should look like with the new sorting layer.

adding-a-new-sorting-layer-in-unity

Now we can move the front of the fireplace to this new layer. Make sure the bottom/front of the fireplace is selected in the Scene tab. In the Inspector panel, find the Sorting Layer property and change it to Front.

Adding and configuring the first (yellow) particle system

Right click in the Hierarchy view and select Create Empty…. Rename the empty object to Fire. We will eventually have three particle systems, one red, one yellow, and one orange as a parent of this empty object.

Now for the first particle system. This is so easy it should be banned. Right-click the Fireplace object in the Hierarchy tab and select Particle System. Rename the particle system to Yellow. Drag the Fire object so it is sitting at the base of the fireplace. Not a bad effect for a couple of clicks of work.

unity-default-particle-system

What we have is a bunch of white particles shooting off in every direction. Let’s think about what needs to change in order to make the yellow of the flame.

  • At the base of the fire, the particles need to be bigger
  • At the top of the fire, the particles need to be smaller and then disappear
  • They need to be yellow (duh!)
  • They need to move upwards, probably a bit more slowly

Make sure Yellow is selected in the Hierarchy tab and then find the Color property in the Inspector tab. It is part of the Yellow module. Click the color property and choose a nice yellow flame color. Instantly the particles will turn yellow. Change the Start Lifetime to 1.8 and the Start Speed to 2. We have now increased the size and reduced the speed of our particles as well as decreased how long they live to just two seconds. This is what the Yellow module in the Inspector panel looks like.

yellow-module

Find the Shape module in the Inspector tab and change it to Edge. In the same module change the Radius to .7. This has changed the shape and width of the emitter. Notice how the particles float upwards, a bit more like fire.

Finally, for the yellow part of the fire, find the Size over Lifetime module. Check the checkbox(circle). Now, Click the graph icon. Now at the bottom of the Inspector tab, we can edit the graph which affects the size of the particle over its lifetime. Make sure the left-hand side of the graph is at the top and the right-hand side is at the bottom. The particles will start off at size two and gradually reduce to zero.

Here is what the graph should look like.

unity-particles-size-over-lifetime

And this is what our fireplace looks like.

yellow-part-of-fire-particle-system

Now we will make the red and orange parts of the fire.

Combining two more particle systems to make a flame effect

Right-click the Yellow object in the Hierarchy tab and select Copy. Right-click the Fire object and select Paste. Rename the new object Red. Make sure the Red object is selected and in the Inspector tab change its Color property to a red color. Change its Start Size to 1.5, a bit smaller than the yellow particles.  Now copy and paste the Yellow object again, rename it to Orange and change its Color property to an orange color. Change its Start Size to 1.0, a bit smaller than the red particles. Make sure that the three particle systems are all children of the Fire object. You can drag and drop them onto it if necessary.

child-red-yellow-and-orang-particle-systems-of-fire-object

Run the game to take a look.

unity-fireplace-effect-before-the-smoke

The effect isn’t bad, but it’s not quite done yet.

 Creating the smoke particle system

We will pretend that this expensive metal fireplace is outside in the garden and a gentle breeze is blowing in from the left. We can then create a column of smoke winding upwards and to the right. Add a new, fresh particle system to the Fire object by right-clicking in the Hierarchy tab and selecting Particle System. Rename it to Smoke and drag it onto the Fire object. We are going to leave it as a cone-shaped emitter this time.

Edit the Color property to be a dark gray color. But when you have the color selector window notice the bottom slider. This is alpha (transparency). This is just what we need for smoke effects. Slide the transparency slider to roughly the middle as shown.

smoke-partices-are-semi-transparent

Select a Start Speed of 1 (nice and slow) and a Start Size of 2.5 so the particles overlap each other and their transparency creates a realistic effect. The absolute final setting is in the Force over Lifetime module. Check the checkbox(circle) of the Force over Lifetime module and then you should set x to 1. Run the game.

unity-fireplace-effect-finnished-project

Smokin’!

What next?

There is so much more that you can do with particle systems, especially in Unity. It wouldn’t be too hard to spend a bit more time tweaking the one we have just made to make the fire more realistic. If you have got a bug for creating particle effects then I suggest you turn to YouTube where there are dozens of particle effects tutorials ranging from rocket boosters to magic effects. In addition, you could take a look at this official Unity particle effects video. It is a one-hour-long video and doesn’t actually make many effects but it does cover all the configuration modules of the Unity particle system. It also shows you how to quickly use particle effects from the Unity asset store.

If you have been following along from the start of my C# tuorials and Unity projects series then the next step is the Simple character animation tutorial. After that, we will make a fully-playable platform game.

patreon