How do I add Particle Effects to Any Object

Below is a tutorial on how to add a particle effect to any Entity in the Editor.

{|
 * style="width: 1100px;" |

What Is A Particle Effect?
A particle effect or particle system, is a collection of 2D sprites that spawn in a given pattern to give the illusion of fluid structures in a game, such as fire, smoke, or a magic spell. They are created by having a collection of very small 2D sprites spawn in a given volume at a high frequency, and then do a specific movement to mimic the effect you want. In The Endless Library in the Editor, there are many pre-made particle effects that you can easily add to any Entity in your project to really bring your game to life.



{|
 * }
 * }
 * style="width: 1100px;" |

How To Add A Particle Effect to An Object
This section will show how to add a particle effect to any Entity in your scene. If you do not currently have a scene you are working in, open "Barebones Game" in your editor.


 * 1) Find an Entity in your Library that you want to add a particle effect to. In this example, we will be adding a particle effect to a rock, perhaps depicting that there is something special about this particular rock. For this example we will be using "Rock Large 01". Please reference How do I Find a Specific Asset? for a tutorial on how to search for a specific item in your library.
 * 2) Drag "Rock Large 01" from the your Library into your Project Hierarchy. Drag it onto "Gameplay" in your Project Hierarchy.
 * 3) Rename your object to something like "Rock with Particles", so it will be easier to find. Rename an item by clicking in it in your Project Hierarchy, and then changing its name in the Inspector window that appears.
 * 4) Right-click on "Rock with Particles", and click "Create Empty" from the menu that appears. Rename this object you just created to "Particle Spawner". This empty entity that you just created will be the origin of the particle effect you are about to add.
 * 5) If the object you are using is particularly large, you may not be able to see the particles, so make sure the new "Particle Spawner" object is at the top or sides where you want the player to be seeing the effect.
 * 6) Search the Library for a script named "Particles". You can tell that it is a script because of the scroll icon that appears next to it in the Library.
 * 7) Drag the "Particles" script from the Library onto the empty "Particle Spawner" entity you made in step 4.
 * 8) Now you can choose any particle effect that you want to add to the rock. Search "effect" in the Library, you can use any of the effects that appear, but for this example, we will use "EMP Impact Effect".
 * 9) Click on the "Particle Spawner" child of "Rock with Particles". Drag "EMP Impact Effect" onto the "Particles To Spawn" field that is on the "Particles" script where it currently says "None".
 * 10) Click the check box next to where it says "Play Particles On Start" on the "Particles" script. This will play the particles when you start the game.
 * 11) Press the blue "Play" button at the top of the scene. During the game, look at the rock with the particle effect on it, there should be lightning emanating from it.



{|
 * }
 * }
 * style="width: 1100px;" |

Play the Particle Effect When you Open Up a Door
Before starting this tutorial, please complete "How To Add A Particle Effect to An Object".


 * 1) Search for "Door" in the Library, and drag Door into the scene on "Gameplay" in the Project Hierarchy. Position it in front of the player so it will be easy to test once you have everything in the scene.
 * 2) Click on the Door that you just dragged into the scene. Uncheck the box that says "Door Locked At Start" on the "Smart Door" script attached to it. This will allow the door to open simply by walking up to it., not requiring a key.
 * 3) On the "Smart Door" script, press the "+" icon below the "On Open" Endless Event. Whatever functions that you call here will be called once the door is opened.
 * 4) Drag the the "Particle Spawner" child of "Rock with Particles" onto the "On Open" Endless Event, where it currently says "No Target". Once you have "Particle Spawner" on that slot, select "SpawnAndPlay" from the dropdown below it. This will make the particles appear once you open the door.
 * 5) Click on "Rock with Particles" from the previous part and click on its child, "Particle Spawner". Uncheck "Play Particles On Start", so that nothing plays when you play the game.
 * 6) Press the blue "Play" button at the top of the scene. Walk up to the door so that it opens. Once it is completely open, you should see the particle effect play on the rock, indicating that the door has been opened.



{|
 * }
 * }
 * style="width: 1100px;" |

Play the Particle Effect Only When You Are In A Certain Area
This section will detail how to play a particle effect only when you are in a certain area. This is helpful if you want to draw attention to something when you are in a certain area. You should have already completed "How To Add A Particle Effect to An Object" and thus have a particle effect ready to activate.


 * 1) First, add a trigger volume to your scene, referencing this tutorial: How do I add a Trigger Volume to Any Item. For this tutorial, we will be positioning it at (0, 0, 0), and scaling it to (7, 7, 7).
 * 2) Click on the Entity that has the TriggerVolume script attached to it. Press the "+" button underneath the "Trigger Enter" Endless Event.
 * 3) Drag the Entity that has the "Particles" script attached to it onto where it says "Target". Click on the dropdown where it currently says "No Function", and select "SpawnAndPlay". This will spawn the particles when you enter the trigger volume. You can press the blue "Play" button at the top of the screen, and walk your character to where the trigger volume exists in the world. You should see the particle effect play when you enter the trigger volume in your scene.
 * 4) Click on the Entity that has the TriggerVolume script attached to it. Press the "+" button underneath the "Trigger Exit" Endless Event.
 * 5) Drag the Entity that has the "Particles" script attached to it onto where it says "Target" on "Trigger Exit". Click on the dropdown where it currently says "No Function", and select "StopParticles". This will stop the particles when you exit the trigger volume. You can press the blue "Play" button at the top of the screen, and walk your character through the trigger volume. The particles should play once you enter the trigger volume, and stop playing once you exit the trigger volume.



{|
 * }
 * }
 * style="width: 1100px;" |

Play One Particle Effect When you are close, and Another When You Are Far Away
Before starting this tutorial, please complete "Play the Particle Effect Only When You Are In A Certain Area". Having another particle effect play when you are far away is fairly simple, it is just a matter of adding another Entity with another particle script attached to them.


 * 1) Start by completing the previous section, connecting a particle effect to a trigger volume.
 * 2) Create another particle effect to be played when you are far away, by following "How To Add A Particle Effect to An Object" with a new empty entity. Name this new empty particle effect you created "Particle Effect Far", this will represent the particle effect that plays when you are not in the trigger volume.
 * 3) Move "Particle Effect Far" to the exact position of the particle effect you already had in the scene. You can view the exact position of the old particle effect by clicking on the Entity in the Project Hierarchy, and then looking at its position in the Inspector window that appears.
 * 4) Next, click on the Entity that has the TriggerVolume script attached to it. Press the "+" button below "Trigger Enter", you should now have 2 events underneath "Trigger Enter".
 * 5) Drag "Particle Effect Far" to where the new event says "Target", and select  "StopParticles" from the dropdown where it currently says "No Function". This should be opposite of what the other particle effect currently does, thus having one particle effect stop right when the other one is starting.
 * 6) Repeat step 4 and 5, except choose "Trigger Exit", and set the function to be called to "SpawnAndPlay".
 * 7) You now should play your game, having one particle effect play when you are close, and another one play when you are far away.




 * }
 * }