Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Mar 27, 2024

Particle System in Unity

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

Introduction

The Particle System in Unity is a flexible, robust system with numerous choices and configurable parameters that allow you to build an infinite number of highly customizable effects. The system gives everyone efficient control and capabilities in creating exactly what they desire.

Particle systems are efficient in creating dynamic items such as fire, smoke, or liquids.

The system decides the particle's lifespan, and when that lifetime ends, the particle is destroyed. Particle systems can be components that can be added to any GameObject in the scene.

Particle System

The Particle System effects might include everything from fire to water, fluid simulations, and cartoon explosions. The system gives both novices and specialists the same degree of control and robust capabilities in creating exactly what they desire.

Particle systems are helpful when creating dynamic items such as fire, smoke, or liquids since these objects are complex to describe using a Mesh(3D) or Sprite (2D). Solid things, such as homes or vehicles, are best represented using meshes and sprites.

A particle system simulates and produces numerous little pictures or Meshes, known as particles, to create a visual effect. Each particle in a system represents a unique graphical element in effect. The technology replicates each particle collectively to produce the illusion of the full effect.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Adding a Particle System

A particle system produces particles at random points inside a predetermined space, which can have a sphere or a cone form. The system decides the particle's lifespan, and when that lifetime ends, the particle is destroyed. Particle systems can be components that can be added to any GameObject in the scene.

There are various methods for incorporating a particle system into your project:

1. To add 3 Particle System to an existing GameObject, select it in the Inspector window, click the Add Component button and type Particle System into the search area.

 

Source: Raywenderlich

2. Select GameObject > Effects > Particle System from the top menu dropdown.

The Particle System attributes will appear in the Inspector tab when you create a particle system.

Source: LearnUnity

Particle System Properties

The Particle System will appear as a game object in the Hierarchy pane. Particle Sprites will populate the Scene randomly in an upward direction in the Scene window. You may choose this Particle System either from the Scene or the Hierarchy.

The particle system Component you added contains numerous subsections, as you can see. Each of these subsections is referred to as a Module. These Modules include the particle system's settings. The Module that is enlarged by default is the Main module. In Unity, the Main module is the backbone of any particle system. The most basic particle settings are discussed below:

Source: Raywenderlich

  • Duration: It controls how long the Particle will play if Looping is not checked.
     
  • Looping: Determines whether the particle loops or only plays once.
     
  • Prewarm: It’s Used when looping is enabled. The Particle System will respond if it has already completed a full cycle on starting.
     
  • Start Delay: The time in seconds before the particle system begins releasing particles.
     
  • Start Lifespan: The particle's initial lifetime in seconds. After this period has passed, the particle is destroyed.
     
  • Start Speed: The particle's starting speed. The faster the particles move, the more dispersed they get.
     
  • 3D Start Size: Changes the Start Size from a constant to a vector in 3D.
     
  • Start Size: The particle's initial size.
     
  • 3D Start Rotation: Changes the start rotation from a constant to a vector in 3D.
     
  • Start Rotation: The particle's starting rotation angle.
     
  • Flip Rotation: Sets the value to 1 to invert the rotation angle along the horizontal axis.
     
  • Start Color: The particle's original color.
     
  • Gravity Modifier: Scales the Gravity value set in the Physics Manager window of Unity. If it is set to O, gravity will be disabled.
     
  • Simulation Space: Particles in Local Space should be moved together with the Particle System. Once emitted, particles in World Space travel freely.
     
  • Simulation Speed: Affects the speed at which the particles are simulated.
     
  • Scaling Mode: Alters the scaling mode between Local, Shape, and Hierarchy.
     
  • Play on Awake: When activated, Play on Awake begins broadcasting instantly.
     
  • Emitter Velocity: Changes the emitter's velocity from Rigidbody to Transform.
     
  • Max Particles: The maximum number of particles that can be alive simultaneously for the particular Particle System. It will stop emitting particles after the limit has been reached.
     
  • Auto Random Seed: This allows the spawning to be auto seeded for more random particle production.
     
  • Stop Action: When the Particle System is halted, and all particles have perished, this action determines whether the Particle System will disable or destroy itself.
     

Particle System Scripting

There are extra Module-specific parameters available for each Module. The Particle System in Unity also allows you to access, alter, and disable Particle Systems using scripts. Like the Particle System, it provides a comprehensive and diverse approach for influencing Particle Systems via code. You may access the Particle System after adding three Particle Systems to a GameObject.

We can get the Particle System component via script:

ParticleSystem part = GetComponent<ParticleSystem>();

 

Now you may explore the ParticleSystem variable to access all of the other methods and functions. You may also use code to start or stop the Particle System.

var part = GetComponent<ParticleSystem>();
part.Play();
Destroy(gameObject, part.main.duration);

Frequently Asked Questions

How can we add a Particle System to an Object?

Select GameObject > Effects > Particle System from the top menu dropdown.

How does the Particle System function in Unity?

A particle system simulates and produces numerous little pictures or Meshes, known as particles, to create a visual effect. Each particle in a system represents a unique graphical element in effect. The technology replicates each particle collectively to produce the illusion of the entire effect.

What are modules?

The particle system Component contains numerous subsections, each of these subsections is referred to as a Module. These Modules include the particle system's settings.

What does a Gravity Modifier do in a Particle System?

It scales the Gravity value set in the Physics Manager window of Unity. If it is set to O, gravity will be disabled.

Conclusion

This article extensively discussed the Particle System in Unity in this article. We start with a brief introduction of the Particle System, its properties, and addition to Unity objects and then move on to the Particle System Scripting. After reading about Particle System in Unity, are you not feeling excited to read/explore more articles on this topic? Don't worry; Coding Ninjas has you covered. To learn, see Operating SystemUnix File SystemFile System Routingand File Input/Output.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive Programming, JavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But suppose you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problems, interview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Topics covered
1.
Introduction
2.
Particle System
3.
Adding a Particle System
4.
Particle System Properties
5.
Particle System Scripting
6.
Frequently Asked Questions
6.1.
How can we add a Particle System to an Object?
6.2.
How does the Particle System function in Unity?
6.3.
What are modules?
6.4.
What does a Gravity Modifier do in a Particle System?
7.
Conclusion