Using particle systems from C#
Once you have created a particle system in the particle editor there are many ways to create and interact with it in game from the C# API.
It is important to understand how control points work before creating particle systems in code, when you call Particles.SetPosition you are not directly setting the position of the system itself but rather the position of a control point that can then be used within the particle system itself.
Particle systems can be created both on the server and client - when created on the server they are automatically networked to all clients along with any of their control point values. When they are created on the client they are visible for that client only.
When creating particles they can be attached to an entity.
When you do this two things happen:
- The lifetime of this particle system is determined by the entity, when the entity is destroyed so is the particle system.
- Control point 0 is set to the entity (or its attachment) position, and will follow it.
Particle systems can be destroyed at any point in your code via a reference to the particle system.
When you destroy a particle system non immediately, the following happens:
- The emitters within the system stop emitting.
- Particles within the system that have emitted began their lifespan decay.
- The end cap is played.
When destroyed immediately none of that happens, all particles within the system are immediately deleted.
Particles can be predicted, this means when you're creating particles in a predicted method such as Simulate it is expected to be called from both the server and client - if you fail to predict it properly it may not show up for your simulated client.