Playing A Particle System Through Script (C#)

Hello, everyone.
Let me get straight to the point:
My game is advanced Roll A Ball, and I want to add particles when falling off a platform.
My DeathFall script (that should play the particles when falling, and restart the scene after that- Y -60 to be exact) is a component of the Player, and so is the ParticleSystem.
I want the ParticleSystem to play between Y -20 and Y -60. Here is my DeathFall script:

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class DeathFall : MonoBehaviour {

    public ParticleSystem tpc;

    void Start()
    {
        tpc = gameObject.GetComponent<ParticleSystem> ();
        tpc.emissionRate = 0;
        tpc.enableEmission = false;
        // None of this is working!
    }

    void Update()
    {
        if(gameObject.transform.position.y <= -20 && gameObject.transform.position.y >= -60)
        {
            tpc.emissionRate = 1;
            // This neither!
            tpc.Play();
            // And this doesn't work too!
        }
        if(gameObject.transform.position.y <= -60)
        {
            SceneManager.LoadScene(Application.loadedLevel);
            //This restarts the game
        }
    }
}

I’ve attached the ParticleSystem component of the Player in the “Tpc” slot of the DeathFall script component in the Player.
Thank you in advance.

I am having the same issue.

We have some functions that should play all particlesystems on a gameObject (and its children).
E.g. you have an explosion with multiple (different) particlesystems as children on it. All the systems have playOnAwake set to false.

The same issues as yours occur.

However, when I change the Simulation Space to World the particles do play!
In our scene it seems all particle systems set to Local are causing issues. They all seem incorrect (position, orientation, etc.)

There is nothing (useful) mentioned in the 5.3 upgrading guide either. This really feels like a bug.

Edit: While looking again - it seems - in my case that the particle system is only played once!
I was testing the issue with a muzzleflash particle system which was really short so I missed the first play. All subsequent calls to play are ignored.

Did you debug it and make sure its at that coords your looking for in your if statement? That would be the first step to make sure that happens… or not.

public float engineRevs;
        public float exhaustRate;

        ParticleSystem exhaust;


        void Start () {
            exhaust = GetComponent<ParticleSystem>();
        }
   

        void Update () {
            exhaust.emissionRate = engineRevs * exhaustRate;
        }
ParticleSystem part = GetComponent<ParticleSystem>();
  part.enableEmission = true;

This is another way you can try.

1 Like

I am having the same issue.
have here:Particle Start Delay Error in 5.3.1P1 - Questions & Answers - Unity Discussions
I do not know why, I was there in 5.2, these particles are correct

Still not working…
Do I need to assign any values to engineRevs and exhaustRate in the inspector?
Sorry,I’m still new to Unity.

I put it to World Simulation Space and it still isn’t working… I also don’t know how to make explosions, so I only have one (stupid) ParticleSystem component attached to the player(not as a seperate Game Object).

I am doing this on the top off my head.
But isn’t enableEmission deprecated in 5.3? Shouldn’t it be something like part.emission.enable = true; ??
Not sure if this works though!

I was testing a bit more last week as well. I another thread a workaround was mentioned.
You would have to enable subemitters in the particle system (there is no need to actually add a subemitter though)

I have had mixed results with this workaround though. In the end I gave up and I continued work on other parts of the project. It still needs to be done :wink:

In hindsight I might not have switched to 5.3(.1) so quickly. For us this has been the most unstable release for our project thus far.

Unity dev team…Please Update Particles emission API!!!

this issue is Very Critical…